Finish 2010-11-17 12:00:00 UTC

Code 01

by Jirachai Getpreecharsawas

Status: Passed
Results: 371197 (cyc: 13, node: 479)
CPU Time: 0.209
Score: 74242.9
Submitted at: 2010-11-11 16:58:34 UTC
Scored at: 2010-11-11 17:07:28 UTC

Current Rank: 2513th (Highest: 126th )

Comments
Please login or create a profile.
Code
function [thrustRow, thrustCol] = solver(chart, aIndex, bIndex, maxThrottle)

[aRow, aCol] = ind2sub(size(chart(:,:,1)), aIndex);
[bRow, bCol] = ind2sub(size(chart(:,:,1)), bIndex);

aCoord = [aRow aCol];
bCoord = [bRow bCol];

thrustRow = zeros(1, 1);
thrustCol = zeros(1, 1);
vel       = [0 0];
turn      = 1;

pos = aCoord;
des = bCoord;
while( sum(abs(des - pos)) > 0 )
    vel = vel + [chart(pos(1), pos(2), 1) chart(pos(1), pos(2), 2)];
    
    motor = [0 0];
    for i = 1:2
        motor(i) = ( (pos(i) >  des(i)) && ((pos(i) + vel(i) < des(i)) || (pos(i) + vel(i) >= pos(i))) ) * (-vel(i) - 1) + ...
                   ( (pos(i) <  des(i)) && ((pos(i) + vel(i) > des(i)) || (pos(i) + vel(i) <= pos(i))) ) * (-vel(i) + 1) + ...
                   (  pos(i) == des(i) ) *                                                                 (-vel(i)    );
    end
    thrustRow(turn) = motor(1);
    thrustCol(turn) = motor(2);
    
    vel  = vel  + motor;
    pos  = pos  + vel;
    turn = turn + 1;
end

pos = bCoord;
des = aCoord;
while( sum(abs(des - pos)) > 0 )
    vel = vel + [chart(pos(1), pos(2), 1) chart(pos(1), pos(2), 2)];
    
    motor = [0 0];
    for i = 1:2
        motor(i) = ( (pos(i) >  des(i)) && ((pos(i) + vel(i) < des(i)) || (pos(i) + vel(i) >= pos(i))) ) * (-vel(i) - 1) + ...
                   ( (pos(i) <  des(i)) && ((pos(i) + vel(i) > des(i)) || (pos(i) + vel(i) <= pos(i))) ) * (-vel(i) + 1) + ...
                   (  pos(i) == des(i) ) *                                                                 (-vel(i)    );
    end
    thrustRow(turn) = motor(1);
    thrustCol(turn) = motor(2);

    vel  = vel  + motor;
    pos  = pos  + vel;
    turn = turn + 1;
end