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 = 25;
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
|