| Code: | function [dRow,dCol,action,mark] = solver(mainMap,foodMap,myAntMap,opAntMap, ...
myScentMap,opScentMap,myDeathMap,opDeathMap)
% Army ant solver
% Created by Alan Chalker
% 11/6/08
%
% Please leave comments in if you reuse this!!!!!
if opAntMap(3,3)>0 % if another ant present, attack
dRow = 0;
dCol = 0;
action = -1;
else
if mainMap(3,3)==1 % if at base, don't carry
action=0;
else
action=1;
end
%if not carrying, check for sugar in view and go towards it
if foodMap(3,3)==0
if any(foodMap(1:2,:))
dRow=-1;
elseif any(foodMap(4:5,:))
dRow=1;
elseif any(foodMap(3,:))
dRow=0;
else
if isnan(mainMap(2,3))
dRow = round(rand);
elseif isnan(mainMap(4,3))
dRow = round(rand)-1;
else
dRow = round(rand*2) - 1;
end
end
if any(foodMap(:,1:2))
dCol=-1;
elseif any(foodMap(:,4:5))
dCol=1;
elseif any(foodMap(:,3))
dCol=0;
else
if isnan(mainMap(3,2))
dCol = round(rand);
elseif isnan(mainMap(3,4))
dCol = round(rand)-1;
else
dCol = round(rand*2) - 1;
end
end
elseif mainMap(3,3)~=1
% if carrying and not on a base, check for base and go towards it
if any(mainMap(1:2,:)==ones(2,5))
dRow=-1;
elseif any(mainMap(4:5,:)==ones(2,5))
dRow=1;
elseif any(mainMap(3,:)==ones(1,5))
dRow=0;
else
if isnan(mainMap(2,3))
dRow = round(rand);
elseif isnan(mainMap(4,3))
dRow = round(rand)-1;
else
dRow = round(rand*2) - 1;
end
end
if any(mainMap(:,1:2)==ones(5,2))
dCol=-1;
elseif any(mainMap(:,4:5)==ones(5,2))
dCol=1;
elseif any(mainMap(:,3)==ones(5,1))
dCol=0;
else
if isnan(mainMap(3,2))
dCol = round(rand);
elseif isnan(mainMap(3,4))
dCol = round(rand)-1;
else
dCol = round(rand*2) - 1;
end
end
else
%check for obstacles and don't send a bad move
if isnan(mainMap(3,2))
dCol = round(rand);
elseif isnan(mainMap(3,4))
dCol = round(rand)-1;
else
dCol = round(rand*2) - 1;
end
if isnan(mainMap(2,3))
dRow = round(rand);
elseif isnan(mainMap(4,3))
dRow = round(rand)-1;
else
dRow = round(rand*2) - 1;
end
end
end
mark = 0;
% nearbybase=[mainMap(2:4,2)' mainMap(2:4,4)' mainMap(2,3) mainMap(4,3)];
% if any(nearbybase==ones(1,8))
% if myScentMap(3,3)~=100;
% mark=100;
% end
% else
%
% nearbyscents=[myScentMap(2:4,2)' myScentMap(2:4,4)' myScentMap(2,3) myScentMap(4,3)];
% if any(nearbyscents)
% if myScentMap(3,3)~=max(nearbyscents)-1
% mark = max(nearbyscents)-1;
% end
% end
%
%
% end
|