2005-05-18 09:00:00 UTC

# hologram6

Status: Passed
Results: 18563.5005
CPU Time: 78.2835
Score: 1856.66
Submitted at: 2005-05-18 13:29:23 UTC
Scored at: 2005-05-18 16:00:52 UTC

Current Rank: 142nd
Based on: hologram5 (diff)
Basis for: hologram8 (diff)
Basis for: hologram9 (diff)

Jack Snoeyink
18 May 2005
homing if more than a path
Code
```function [dy,dx,mark,carry]=solver(main,food,ants,scent)
%18372.39 or 18293.70
rand(1,5);
i35=3:5;
i24=2:4;
i02=0:2;
% find reachable regions
end
end
end
end
% modify current board based on reachable regions
end
% setup game stats
scents=scent(scent>0);
maxscent=max(scents(:));
% mark this field
if (max(main(:)))
mark=400-scent(13);
scent(13)=400;
init=false;
hills=find(main>0);
scent(hills)=1e7;
food(hills)=0;
if isempty(scents);maxscent=mark;end
elseif (maxscent==min(scents(:))) % init phase
mark=maxscent-scent(13);
scent(13)=maxscent;
init=true;
elseif isempty(scents) % nothing is marked
mark=98;
scent(13)=scent(13)+98;
maxscent=mark;
init=true;
else
mark=maxscent-1-scent(13);
scent(13)=maxscent-1;
init=false;
end

dirx = [-1,2,2,2,-1; 2,-1,-1,-1,2; 2,0,0,0,2; 2,1,1,1,2; 1,2,2,2,1];
diry = [-1,-1,0,1,1; -1,-1,0,1,1; -1,-1,0,1,1; -1,-1,0,1,1; -1,-1,0,1,1];
% look around for food
if init||(max(food(:))<1) % nothing found or no way home, search
[y,x]=find(target==max(target(:)));
if (numel(y)>1)
r=ceil(rand*numel(y));
y=y(r);
x=x(r);
end
carry=food(13)>0;
dx = dirx(x,y);
if dx<2
dy = diry(x,y);
return;
end;
m(7,7)=0;
m(y+i02,x+i02)=1;
m=m(i35,i35);
t=target(i24,i24).*m+m;
[dy,dx]=find(t==max(t(:)));
r=ceil(rand*numel(dy));
dy=dy(r)-2;
dx=dx(r)-2;
return;
end;
if (food(13)>1)&&rand<.95 % sit on a lot of food, go home
[y,x]=find(target==max(target(:)));
if (numel(y)>1)
r=ceil(rand*numel(y));
y=y(r);
x=x(r);
end
carry=1;
dx = dirx(x,y);
if dx<2
dy = diry(x,y);
return;
end;
m(7,7)=0;
m(y+i02,x+i02)=1;
m=m(i35,i35);
t=target(i24,i24).*m+m;
[dy,dx]=find(t==max(t(:)));
r=ceil(rand*numel(dy));
dy=dy(r)-2;
dx=dx(r)-2;
return;
end;
if (food(13) >= 1) % sit on one food, build track
[yhome,xhome]=find(target==max(target(:)));
carry=1;
dh = max(abs(yhome-3),abs(xhome-3));
nb1 = [7 8 9 12 14 17 18 19];
up = scent(nb1)>=scent(13);
nu = nb1(up);
if (min(dh)>1)||(sum(food(nu)>0)<2-(numel(nu))<2)||(sum(food(nb1(~up))>0)<2)
target=food;
target(scent>=scent(13))=0;
dhere=max(dh);
target(i24,i24)=target(i24,i24)*1000;
runs=sum(target(:)>0);
while runs % fetch food behind
[y,x]=find(target==max(target(:)));
if (numel(y)>1)
r=ceil(rand*numel(y));
y=y(r);
x=x(r);
end
dx = dirx(x,y);
if dx<2
dy = diry(x,y);
else
m(7,7)=0;
m(y+i02,x+i02)=1;
m=m(i35,i35);
t=target(i24,i24).*m+m;
[dy,dx]=find(t==max(t(:)));
r=ceil(rand*numel(dy));
dy=dy(r)-2;
dx=dx(r)-2;
end
if ( min(max(abs(yhome-y),abs(xhome-x))) > dhere )
carry=0;
return;
end
target(y,x)=0;runs=runs-1;
end
end
%   if (carry) % go home
[y,x]=find(target==max(target(:)));
if (numel(y)>1)
r=ceil(rand*numel(y));
y=y(r);
x=x(r);
end
dx = dirx(x,y);
if dx<2
dy = diry(x,y);
return;
end;
m(7,7)=0;
m(y+i02,x+i02)=1;
m=m(i35,i35);
t=target(i24,i24).*m+m;
[dy,dx]=find(t==max(t(:)));
r=ceil(rand*numel(dy));
dy=dy(r)-2;
dx=dx(r)-2;
return;
%  end
return;
end;
[y,x]=find(target==max(target(:)));
if (numel(y)>1)
r=ceil(rand*numel(y));
y=y(r);
x=x(r);
end
carry=0;
dx = dirx(x,y);
if dx<2
dy = diry(x,y);
return;
end;
m(7,7)=0;
m(y+i02,x+i02)=1;
m=m(i35,i35);
t=target(i24,i24).*m+m;
[dy,dx]=find(t==max(t(:)));
r=ceil(rand*numel(dy));
dy=dy(r)-2;
dx=dx(r)-2;```