2005-05-18 09:00:00 UTC

# Gt03

by Jin

Status: Passed
Results: 29356.0643
CPU Time: 78.9312
Score: 2935.94
Submitted at: 2005-05-18 13:27:33 UTC
Scored at: 2005-05-18 15:52:32 UTC

Current Rank: 1420th
Based on: Gt02 (diff)

Jin
18 May 2005
This my ants tweaked from 'bedlam'.It's good in open map, but not good in closed map.So I just submit it to celebrate my this contest. :)
Code
```function [dy,dx,mark,carry] = mysolver(main,food,ants,scent)
%SOLVER The ant brain.

%% from 'bedlam'
nr = main(:) > -1;
nb1 = [7 8 9 12 14 17 18 19];
n1 = nb1(nr(nb1));
mark = 0;
carry = false;%false->true

dist = [2.81,2.48,2.01,2.43,2.86, 2.42,1.41,1.01,1.40,2.40, 2.03,1.04,0,1.02,2.02, 2.41,1.43,1.00,1.42,2.44, 2.85,2.45,2,2.47,2.83];
dirx = [-1,-1,-1,-1,-1, -1,-1,-1,-1,-1, 0, 0, 0, 0, 0,  1, 1,1, 1, 1,  1, 1,1,1,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];

nb2 = [1  5 21 25  2  4  6 10 16 20 22 24  3 11 15 23];

nb2X = all(nr([1  5 21 25  2  4  6 10 16 20 22 24  3 11 15 23;
7  9 17 19  7  9  7  9 17 19 17 19  8 12 14 18]));
nb2n = nb2(nb2X);
n2 = [n1 nb2n];
n3 = [13 n2];

%% Scanning the things in ant's scope
tp = ants(13);
ants(13) = 0;
home = n3(main(n3)==1);
food = max(food-ants,0);
food(home)= 0;
ants(13) = tp;

myfood = (food(13)>0) && ~main(13);

%%
if ~isempty(nb2n)
toi = nb2n(ceil(rand*length(nb2n)));
else
toi = n1(ceil(rand*length(n1)));
end

%%

%% mark
maxs = max(scent(n2));
mins = min(scent(n2));
init = false;
if (~isempty(home))
mark = 100-2*dist(home(1)); %mark = 400-scent(13);
%init = 0;
elseif (maxs == 0) % nothing is marked
%     mark = 10;
init = true;
else
mark = maxs-2-scent(13);
%init = 0;
end

%% walk in initial state
if (init) % nothing found or no way home, search %remove:~any(food(:)) ||
carry = food(13) > 0;
dx = dirx(toi);
dy = diry(toi);
return
end

%% walk
if myfood % go home
carry = true;
if (~isempty(home))
toi = home(1);
mark = 0;
else

[m,i] = max(scent(n2)); %n2->:
if (m > 0) && (ants(13)<=2)
toi = n2(i);
mark = 0;
end

end
else % find food
f = n2(find(food(n2)));% No.of food;remove:& ~main(n2)
if ~isempty(f)
toi = f(1);
else
if ants(13) <= 2 % remove rand*
s = n2(scent(n2) == mins);%sum(ants(:))->2
toi = s(ceil(rand*length(s)));
end
end

end

dx = dirx(toi);
dy = diry(toi);

```