2005-05-18 09:00:00 UTC

justwant1topass

Status: Passed
Results: 36438.3650
CPU Time: 143.41
Score: 3855.25
Submitted at: 2005-05-18 15:22:00 UTC
Scored at: 2005-05-18 18:53:45 UTC

Current Rank: 1565th

J LeBlanc
18 May 2005
Just thought this would help to learn Matlab quickly,
wanted to see what I could get on my own, without
looking around (too much) at everyone else's work.
Code
```function [dy,dx,mark,carry] = solver(M,F,A,Sin)
%SOLVER The ant brain.
%   30900 before I broke something :)

S=Sin;

% squares I can't reach
end;
end;
end;
end;
end;
% modify current board based on reachable regions
B=zeros(5,5);

% anthills I can reach
homes=find(M(:)==1);
F(homes)=0;

% size and direction of biggest scent trail
S(13)=0;
S(A>0)=S(A>0)-4;
[Smax,Hdir]=max(S(:));

% markings indicate the way home
if not(isempty(homes))
mark=100;
elseif Smax>15
mark=max(Smax-rem(Smax,5)-Sin(13),0);
else
mark=max(15-Sin(13),0);
end;
if mark>100
mark=100;
end;

if F(13)>0                          % bring food home
carry = true;
mark=max(15-Sin(13),0);
if not(isempty(homes))
target=homes(1);
elseif Smax>15
target=Hdir;
else
target=26-(Hdir);
end;
else
carry = false;
ff=F-A; % free food
if max(ff(:))>0                 % go towards visible free food
mark=mark-10;
ffwhere = find(ff>0);
n1=1;
target=ffwhere(1);
while and( B(target)==1, n1<length(ffwhere) )
n1=n1+1;
target=ffwhere(n1);
end;
else                                % no visible free food
if (rand(1)>0.25)&&(B(26-(Hdir))==0)
target=26-(Hdir);
else
if isempty(myod)
target=13;
else
any=(ceil(length(myod).*rand(1)));
target = myod(any);
end;
end;
end;
end;

[dy,dx] = go1(target);

if B(3+dy,3+dx)==1
if length(myod)==1
[dy,dx] = go1(myod(1));
else
any=(ceil(length(myod).*rand(1)));
if (dx==0)||(dy==0) % target among [3,23,11,15]
if B(3+dx+dy,3+dx+dy)==0 % try diagonal
dx=dx+dy;
dy=dx;
elseif B(3+dy-dx,3+dx-dy)==0 % other diagonal
dy1=dy-dx;
dx1=dx-dy;
dy=dy1;
dx=dx1;
else
[dy,dx]=go1(myod(any)); % can only move away anyhow
end;
elseif ismember(target,[1,5,21,25]) % want to go to a corner
if B(3+dy,3)==0
dx=0;
elseif B(3,3+dx)==0
dy=0;
else
[dy,dx]=go1(myod(any));
end;
elseif ismember(target,[2,4,22,24])
if B(3,3+dx)==0
dy=0;
else
[dy,dx]=go1(myod(any));
end;
else  % target among [6,10,16,20]
if B(3+dy,3)==0
dx=0;
else
[dy,dx]=go1(myod(any));
end;
end;
end;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [DY,DX] = go1(n)
EW = zeros(5,5);
EW(1:10) = -1;
EW(16:25) = 1;
NS = EW';
DY = NS(n);
DX = EW(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
```