| Code: | function [dRow,dCol,action,mark] = solver(mainMap, foodMap, myAntMap, opAntMap, myScentMap, opScentMap, myDeathMap, opDeathMap)
mainMap = mainMap(:);
foodMap = foodMap(:);
myAntMap = myAntMap(:);
opAntMap = opAntMap(:);
myScentMap = myScentMap(:);
opScentMap = opScentMap(:);
myDeathMap = [];
opDeathMap = [];
setSearchDirected = 0.2;
setSearchExpansionistic = 0.3;
setTurnRight = 0.5;
% Fill Nans into blocked spots of some matrices
fieldsImpossible = isnan(mainMap);
foodMap(fieldsImpossible) = nan;
myScentMap(fieldsImpossible) = nan;
foodMap(mainMap==1) = 0;
r = rand(8,1);
% center = [ 13 ];
% smallsquare = [ 7 8 9 12 13 14 17 18 19 ];
% smalleye = [ 7 8 9 12 14 17 18 19 ];
% bigeye = [ 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25];
smalleyetodir = [ 7 6 5 0 4 1 2 3 ];
bigeyetodir = [ 7 7 6 5 5 7 7 6 5 5 0 0 4 4 1 1 2 3 3 1 1 2 3 3];
smalleye = [false; false; false; false; false; false; true; true; true; false; false; true; false; true; false; false; true; true; true; false; false; false; false; false; false];
bigeye = [true; true; true; true; true; true; true; true; true; true; true; true; false; true; true; true; true; true; true; true; true; true; true; true; true];
translateDirectionToMap = [12 17 18 19 14 9 8 7];
% init
action = 0;
moveDirection = -1;
doTumble = false;
% SCENT
if any(mainMap(:) == 1, 1) mark = 100;
else mark = floor((max(myScentMap(:))-myScentMap(13)-1) ./ myAntMap(13));
end
if mark < 0 mark = 0;
elseif mark > 100 mark = 100;
end
if opAntMap(13)
action = -1;
moveDirection = -1;
% elseif any(opAntMap(:), 1) % hunt ants
% action = -1;
% if opAntMap(13)
% moveDirection = -1;
% elseif any(opAntMap(smalleye), 1)
% [dummy, smalleyedir] = max(opAntMap(smalleye)); %#ok<ASGLU>
% moveDirection = smalleyetodir(smalleyedir);
% else % opAnt in bigeye
% [dummy, bigeyedir] = max(opAntMap(bigeye)); %#ok<ASGLU>
% moveDirection = bigeyetodir(bigeyedir);
% end
elseif foodMap(13) && r(5) < (foodMap(13) / myAntMap(13)) % food here, and we are a carrier -> MOVE HOME
action = 1;
homeseen = mainMap(bigeye) == 1;
if any(homeseen, 1) % move towards home
bigeyedir = find(homeseen(:), 1, 'first');
moveDirection = bigeyetodir(bigeyedir);
else % move towards max scent
[maxscent, bigeyedir] = max(myScentMap(bigeye)); %#ok<ASGLU>
if maxscent > 0
moveDirection = bigeyetodir(bigeyedir);
else
moveDirection = ceil(r(7)*8)-1;
end
end
elseif any((foodMap(bigeye) - myAntMap(bigeye)) > 0) % if no opAnts are around, move to food
[dummy, bigeyedir] = max(foodMap(bigeye)); %#ok<ASGLU>
moveDirection = bigeyetodir(bigeyedir);
doTumble = true;
% elseif any(opScentMap(bigeye) > 0, 1) && r(2) < 0.5 % opponent's scent seen & rand
% [dummy, bigeyedir] = max(opScentMap(bigeye)); %#ok<ASGLU>
% moveDirection = bigeyetodir(bigeyedir);
% doTumble = true;
else
% SEARCH
if r(1) < setSearchDirected
maxscent = max(myScentMap(bigeye));
if maxscent > 0
direction = find(myScentMap(bigeye) >= maxscent);
ndirections = numel(direction);
if ndirections > 1
direction = direction(ceil(r(6)*ndirections));
end
moveDirection = mod(bigeyetodir(direction) + 4, 8);
doTumble = true;
else
moveDirection = ceil(r(7)*8)-1;
end
elseif r(1) < setSearchExpansionistic
maxants = max(myAntMap(bigeye));
if maxants > 0
direction = find(myAntMap(bigeye) >= maxants);
ndirections = numel(direction);
if ndirections > 1
direction = direction(ceil(r(8)*ndirections));
end
moveDirection = mod(bigeyetodir(direction) + 4, 8);
doTumble = true;
else
moveDirection = ceil(r(7)*8)-1;
end
else
moveDirection = ceil(r(7)*8)-1;
end
end
% FIXMOVE
if moveDirection >= 0
% TUMBLE
if doTumble
if r(3) < 0.2 moveDirection = mod(moveDirection - 1, 8);
elseif r(3) > 0.8 moveDirection = mod(moveDirection + 1, 8);
end
end
target = translateDirectionToMap(moveDirection+1);
if isnan(mainMap(target)) || opAntMap(target)
%decide direction to rotate
% turn = 1-2*(r(4)<setTurnRight);
%
% for j = 1:7
% moveDirection = mod(moveDirection + turn, 8);
% target = translateDirectionToMap(moveDirection+1);
% if ~isnan(mainMap(target)) && ~opAntMap(target)
% break;
% end
% if j == 7
% moveDirection = -1;
% end
% end
moveDirection = ceil(r(7)*8)-1;
end
end
dRows = [0 -1 -1 0 1 1 1 0 -1];
dCols = [0 0 1 1 1 0 -1 -1 -1];
dRow = dRows(moveDirection+2);
dCol = dCols(moveDirection+2);
end
|