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

random round one

by Alex P.

Status: Passed
Results: 470652 (cyc: 7, node: 397)
CPU Time: 6.01
Score: 94130.8
Submitted at: 2010-11-10 19:24:37 UTC
Scored at: 2010-11-10 19:25:10 UTC

Current Rank: 2967th (Highest: 1st )

Comments
Please login or create a profile.
Code
function [thrustRow, thrustCol] = solver(chart, aIndex, bIndex, maxThrottle)
% Basic solver, does random, and compare some
thrustRow = [1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 1];
thrustCol = [0 0 0 0 0  1 0 0 0 0 -1 0 0 0 -1];
[dA,dB] = runsolution(thrustRow, thrustCol, chart, aIndex, bIndex);
solverScore = scoresolution(dA,dB,thrustRow,thrustCol);

for k = 1:100
    L = 15;
    tR = round(2*rand(L,1)-1);
    tC = round(2*rand(L,1)-1);
    [dA,dB] = runsolution(tR, tC, chart, aIndex, bIndex);
    Sc = scoresolution(dA,dB,tR,tC);
    
    if Sc < solverScore
        thrustRow = tR;
        thrustCol = tC;
        solverScore = Sc;
    end
end
end

function [dA, dB] = runsolution(thrustRow, thrustCol, chart, aIndex, bIndex)
rowWind = chart(:,:,1);
colWind = chart(:,:,2);
[nR,nC] = size(rowWind);
[AR,AC] = ind2sub([nR,nC],aIndex);
[BR,BC] = ind2sub([nR,nC],bIndex);
fR = AR; fC =AC;
fvR = 0; fvC = 0;
dB = (fR-BR)^2 + (fC-BC)^2;
for i = 1:numel(thrustRow)
    ivR = fvR + thrustRow(i) + rowWind(fR,fC);
    ivC = fvC + thrustCol(i) + colWind(fR,fC);
    iR = fR + ivR;
    iC = fC + ivC;
    if iR>nR || iR<1 || iC>nC || iC<1
        break
    end
    fR = iR;
    fC = iC;
    fvR = ivR;
    fvC = ivC;
    if ((fR-BR)^2 + (fC-BC)^2) < dB
        dB = (fR-BR)^2 + (fC-BC)^2;
    end
end
dA = (fR-AR)^2 + (fC-AC)^2;
end

function score = scoresolution(dA,dB,thrustRow,thrustCol)
score = dB + dA + sum(abs(thrustRow)) + sum(abs(thrustCol));
end