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

fast speed boat 20000

by Alex P.

Status: Failed
Results: Failed (timeout)

Comments
Please login or create a profile.
Code
function [thrustRow, thrustCol] = solver(chart, aIndex, bIndex, maxThrottle)
rowWind = chart(:,:,1);
colWind = chart(:,:,2);
[nR,nC] = size(rowWind);
[AR,AC] = ind2sub([nR,nC],aIndex);
[BR,BC] = ind2sub([nR,nC],bIndex);

rd=BR-AR; cd=BC-AC;
dist = abs(rd)+abs(cd);
thrustRow = [1 zeros(1,rd)  -1 zeros(1,cd)  -1 zeros(1,rd)  1 zeros(1,cd)] * sign(BR-AR);
thrustCol = [zeros(1,rd) 1  zeros(1,cd) -1  zeros(1,rd) -1  zeros(1,cd) 1] * sign(BC-AC);
[dA,dB] = runsolution(thrustRow, thrustCol, chart, nR,nC,AR,AC,BR,BC);
solverScore = dB + dA + sum(abs(thrustRow)) + sum(abs(thrustCol));

for k = 1:20000
    L = 2*dist;
    tR = round(1.8*(rand(L,1)-0.5));
    tC = round(1.8*(rand(L,1)-0.5));
    fR = AR; fC =AC;
    fvR = 0; fvC = 0;
    dB = (fR-BR)^2 + (fC-BC)^2;
    for i = 1:numel(tR)
        ivR = fvR + tR(i) + rowWind(fR,fC);
        ivC = fvC + tC(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;
    Sc = dB + dA + sum(abs(tR)) + sum(abs(tC));
    
    if Sc < solverScore
        thrustRow = tR;
        thrustCol = tC;
        solverScore = Sc;
    end
end
end

function [dA, dB] = runsolution(thrustRow, thrustCol, chart, nR,nC,AR,AC,BR,BC)
rowWind = chart(:,:,1);
colWind = chart(:,:,2);
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