2005-05-18 09:00:00 UTC

# rip1

Status: Passed
Results: 36586.9366
CPU Time: 155.09
Score: 4338.52
Submitted at: 2005-05-18 16:59:14 UTC
Scored at: 2005-05-19 04:18:06 UTC

Current Rank: 1628th

Corbin Holland
18 May 2005
bleh just checkin
Code
```function [dy,dx,mark,carry] = solver(main,food,ants,scent)
%SOLVER The ant brain.
%
%  INPUTS: (all 5x5 matrices, the ant is located at the center)
%  main  -- anthills (1), impassable regions (-1), and open space (0)
%  food  -- number of sugar cubes
%  ants  -- number of ants (always be at least 1 at (3,3))
%  scent -- strength of chemical scent (decreases by one each time interval)
%
%  OUTPUTS: (all scalars)
%  dy    -- delta in rows (-1 is up, 0 no move, 1 is down)
%  dx    -- delta in columns (-1 is left, 0 no move, 1 is right)
%  mark  -- scent left by the ant, any integer between 0 and 100
%  carry -- logical indicating if the ant will carry one unit of food or not

if rand<.5 && ( (~any(food(:)) && all(scent(:)>10)) || ...
(any(scent(:)>10)&& (rand<1)) ),
dx=0;dy=0;carry=0;
if scent(13), mark=96; else, mark=0; end
return;
end;
c=23;
n=46;
k=96;
switch(ceil(10*rand)),
case 1,
traj=reshape([7,1,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,7,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,8,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,8,4,4,4,4,4,4,4,4,4,9,4,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,7,6,6,6,6,6,6,6,6,6,12,6,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,9,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,12,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,9,15,15,15,15,15,15,15,15,15,14,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,17,16,16,16,16,16,16,16,16,16,12,16,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,17,22,22,22,22,22,22,22,22,22,18,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,19,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,17,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,19,24,24,24,24,24,24,24,24,24,18,24,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 2,
traj=reshape([7,1,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,8,2,2,2,2,2,2,2,2,2,7,2,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,7,3,3,3,3,3,3,3,3,3,8,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,8,4,4,4,4,4,4,4,4,4,9,4,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,7,6,6,6,6,6,6,6,6,6,12,6,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,9,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,7,11,11,11,11,11,11,11,11,11,12,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,14,15,15,15,15,15,15,15,15,15,9,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,12,16,16,16,16,16,16,16,16,16,17,16,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,18,22,22,22,22,22,22,22,22,22,17,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,19,23,23,23,23,23,23,23,23,23,17,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,18,24,24,24,24,24,24,24,24,24,19,24,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 3,
traj=reshape([7,1,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,7,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,9,3,3,3,3,3,3,3,3,3,8,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,9,4,4,4,4,4,4,4,4,4,8,4,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,7,6,6,6,6,6,6,6,6,6,12,6,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,9,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,7,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,12,11,11,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,9,15,15,15,15,15,15,15,15,15,14,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,12,16,16,16,16,16,16,16,16,16,17,16,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,18,22,22,22,22,22,22,22,22,22,17,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,19,23,23,23,23,23,23,23,23,23,17,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,18,24,24,24,24,24,24,24,24,24,19,24,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 4,
traj=reshape([7,1,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,8,2,2,2,2,2,2,2,2,2,7,2,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,8,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,8,4,4,4,4,4,4,4,4,4,9,4,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,12,6,6,6,6,6,6,6,6,6,7,6,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,9,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,12,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,9,15,15,15,15,15,15,15,15,15,14,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,17,16,16,16,16,16,16,16,16,16,12,16,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,18,22,22,22,22,22,22,22,22,22,17,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,18,23,23,23,23,23,23,23,23,23,19,23,23,23,23,23,23,23,23,23,17,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,19,24,24,24,24,24,24,24,24,24,18,24,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 5,
traj=reshape([7,1,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,7,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,7,3,3,3,3,3,3,3,3,3,8,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,9,4,4,4,4,4,4,4,4,4,8,4,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,12,6,6,6,6,6,6,6,6,6,7,6,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,14,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,12,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,14,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,9,15,15,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,12,16,16,16,16,16,16,16,16,16,17,16,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,17,22,22,22,22,22,22,22,22,22,18,22,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,17,23,23,23,23,23,23,23,23,23,19,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,18,24,24,24,24,24,24,24,24,24,19,24,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 6,
traj=reshape([7,1,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,7,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,8,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,9,4,4,4,4,4,4,4,4,4,8,4,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,7,6,6,6,6,6,6,6,6,6,12,6,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,14,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,17,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,12,11,11,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,19,15,15,15,15,15,15,15,15,15,9,15,15,15,15,15,15,15,15,15,14,15,15,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,17,16,16,16,16,16,16,16,16,16,12,16,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,18,22,22,22,22,22,22,22,22,22,17,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,19,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,17,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,18,24,24,24,24,24,24,24,24,24,19,24,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 7,
traj=reshape([7,1,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,8,2,2,2,2,2,2,2,2,2,7,2,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,8,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,8,4,4,4,4,4,4,4,4,4,9,4,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,12,6,6,6,6,6,6,6,6,6,7,6,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,14,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,12,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,14,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,9,15,15,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,12,16,16,16,16,16,16,16,16,16,17,16,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,17,22,22,22,22,22,22,22,22,22,18,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,17,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,19,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,19,24,24,24,24,24,24,24,24,24,18,24,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 8,
traj=reshape([7,1,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,7,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,8,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,9,4,4,4,4,4,4,4,4,4,8,4,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,7,6,6,6,6,6,6,6,6,6,12,6,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,14,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,12,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,14,15,15,15,15,15,15,15,15,15,9,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,17,16,16,16,16,16,16,16,16,16,12,16,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,19,20,20,20,20,20,20,20,20,20,14,20,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,18,22,22,22,22,22,22,22,22,22,17,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,18,23,23,23,23,23,23,23,23,23,19,23,23,23,23,23,23,23,23,23,17,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,19,24,24,24,24,24,24,24,24,24,18,24,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 9,
traj=reshape([7,1,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,8,2,2,2,2,2,2,2,2,2,7,2,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,8,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,9,4,4,4,4,4,4,4,4,4,8,4,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,7,6,6,6,6,6,6,6,6,6,12,6,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,14,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,12,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,9,15,15,15,15,15,15,15,15,15,14,15,15,15,15,15,15,15,15,15,19,15,15,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,17,16,16,16,16,16,16,16,16,16,12,16,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,14,20,20,20,20,20,20,20,20,20,19,20,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,17,22,22,22,22,22,22,22,22,22,18,22,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,19,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,17,23,23,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,18,24,24,24,24,24,24,24,24,24,19,24,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
case 10,
traj=reshape([7,1,1,1,1,1,1,1,1,1,8,2,1,1,1,1,1,1,1,1,12,6,1,1,1,1,1,1,1,1,9,3,2,1,1,1,1,1,1,1,17,11,6,1,1,1,1,1,1,1,8,2,2,2,2,2,2,2,2,2,7,2,2,2,2,2,2,2,2,2,9,3,2,2,2,2,2,2,2,2,12,6,2,2,2,2,2,2,2,2,17,11,6,2,2,2,2,2,2,2,7,3,3,3,3,3,3,3,3,3,9,3,3,3,3,3,3,3,3,3,8,3,3,3,3,3,3,3,3,3,12,6,2,3,3,3,3,3,3,3,14,10,4,3,3,3,3,3,3,3,9,4,4,4,4,4,4,4,4,4,8,4,4,4,4,4,4,4,4,4,7,3,4,4,4,4,4,4,4,4,14,10,4,4,4,4,4,4,4,4,19,15,10,4,4,4,4,4,4,4,9,5,5,5,5,5,5,5,5,5,8,4,5,5,5,5,5,5,5,5,14,10,5,5,5,5,5,5,5,5,7,3,4,5,5,5,5,5,5,5,19,15,10,5,5,5,5,5,5,5,12,6,6,6,6,6,6,6,6,6,7,6,6,6,6,6,6,6,6,6,8,2,6,6,6,6,6,6,6,6,17,11,6,6,6,6,6,6,6,6,9,3,2,6,6,6,6,6,6,6,9,10,10,10,10,10,10,10,10,10,14,10,10,10,10,10,10,10,10,10,8,4,10,10,10,10,10,10,10,10,19,15,10,10,10,10,10,10,10,10,7,3,4,10,10,10,10,10,10,10,17,11,11,11,11,11,11,11,11,11,12,11,11,11,11,11,11,11,11,11,7,11,11,11,11,11,11,11,11,11,18,22,16,11,11,11,11,11,11,11,8,2,6,11,11,11,11,11,11,11,19,15,15,15,15,15,15,15,15,15,14,15,15,15,15,15,15,15,15,15,9,15,15,15,15,15,15,15,15,15,18,24,20,15,15,15,15,15,15,15,8,4,10,15,15,15,15,15,15,15,12,16,16,16,16,16,16,16,16,16,17,16,16,16,16,16,16,16,16,16,18,22,16,16,16,16,16,16,16,16,7,11,16,16,16,16,16,16,16,16,19,23,22,16,16,16,16,16,16,16,19,20,20,20,20,20,20,20,20,20,14,20,20,20,20,20,20,20,20,20,9,15,20,20,20,20,20,20,20,20,18,24,20,20,20,20,20,20,20,20,17,23,24,20,20,20,20,20,20,20,17,21,21,21,21,21,21,21,21,21,12,16,21,21,21,21,21,21,21,21,18,22,21,21,21,21,21,21,21,21,19,23,22,21,21,21,21,21,21,21,7,11,16,21,21,21,21,21,21,21,18,22,22,22,22,22,22,22,22,22,17,22,22,22,22,22,22,22,22,22,19,23,22,22,22,22,22,22,22,22,12,16,22,22,22,22,22,22,22,22,7,11,16,22,22,22,22,22,22,22,17,23,23,23,23,23,23,23,23,23,18,23,23,23,23,23,23,23,23,23,19,23,23,23,23,23,23,23,23,23,14,20,24,23,23,23,23,23,23,23,12,16,22,23,23,23,23,23,23,23,18,24,24,24,24,24,24,24,24,24,19,24,24,24,24,24,24,24,24,24,17,23,24,24,24,24,24,24,24,24,14,20,24,24,24,24,24,24,24,24,9,15,20,24,24,24,24,24,24,24,19,25,25,25,25,25,25,25,25,25,14,20,25,25,25,25,25,25,25,25,18,24,25,25,25,25,25,25,25,25,17,23,24,25,25,25,25,25,25,25,9,15,20,25,25,25,25,25,25,25],[10,5,16]);
end
trajopt=[9,8,8,7,7,9,9,8,8,7,9,9,9,7,7,9,9,8,8,7,9,8,8,7,7,9,9,8,8,7,9,9,8,8,7,9,9,9,7,7,9,9,9,7,7,9,9,8,8,7,9,9,8,8,7,9,8,8,7,7,9,9,8,8,7,9,9,9,7,7,9,9,8,8,7,9,8,8,7,7];
closer=[7:9,12:14,17:19];
far=[1:6,10,11,15,16,20:25];
iscloser=reshape([0,0,0,0,0,0,7:9,0,0,12:14,0,0,17:19,0,0,0,0,0,0],[5,5]);
corner=reshape([6,7,8,9,14,18,4,9,14,19,18,12,20,19,18,17,12,8,22,17,12,7,8,14, 10,9,8,7,12,18, 24,19,14,9,8,12, 16,17,18,19,14,8, 2,7,12,17,18,14],[6,8]);
distances=reshape([.8,.5,.4,.5,.8,.5,.2,.1,.2,.5,.4,.1,.0,.1,.4,.5,.2,.1,.2,.5,.8,.5,.4,.5,.8],[5,5]);
fov=reshape([1,2,3,4,4,6,7,8,9,9,11,12,13,14,14,16,17,18,19,19,16,17,18,19,19,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,16,17,18,19,20,2,3,4,5,5,7,8,9,10,10,12,13,14,15,15,17,18,19,20,20,17,18,19,20,20,1,2,3,4,4,6,7,8,9,9,11,12,13,14,14,16,17,18,19,19,21,22,23,24,24,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,2,3,4,5,5,7,8,9,10,10,12,13,14,15,15,17,18,19,20,20,22,23,24,25,25,6,7,8,9,9,11,12,13,14,14,16,17,18,19,19,21,22,23,24,24,21,22,23,24,24,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,21,22,23,24,25,7,8,9,10,10,12,13,14,15,15,17,18,19,20,20,22,23,24,25,25,22,23,24,25,25],[5,5,9]);
DX=reshape([-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2],[5,5]);
DY=reshape([-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2],[5,5]);

carry=food(13)&(main(13)~=1);

% Scent signal decoding
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
S(5,5) = 0;
idx_t=find(scent);
nscent=length(idx_t);
if ~nscent, mark=100; dx=floor(3*rand)-1; dy=floor(3*rand)-1; return;
elseif nscent==1, % one scent
t=rem(scent(idx_t),k);
else, % several scent
mscent=rem(scent(idx_t),k);
z=zeros(1,k); z(1+mscent)=1; tscent=find(z);
if length(tscent)==1, nill=k; idx=1;
else, [nill,idx]=max([tscent(1)+k-tscent(end),tscent(2:end)-tscent(1:end-1)]); end
if nill<n,
t=nan;
else,
t=tscent(idx)-1;
S(idx_t)=mod(mscent-t,k);
end
end
S_ISTIME=scent&~S;
S_ISFOOD=S>=c;
S(S_ISFOOD)=S(S_ISFOOD)-c+1;
S_ISPATH=S&(S<c);
main(S==c+2)=-1;
R=.25*rand(5);

% Find possible trajectories
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
isreachable=iscloser>0;
[d,idx]=max(all(main(traj)>=0));
isreachable(far(targetpossible))=1;
isreachable(main<0)=0;
if ~any(isreachable(:)), dx=0; dy=0; mark=0; return; end;
newpos=traj(1,idx(:)+(0:5:75)');
leftright=zeros(1,3); updown=zeros(1,3); leftright(2+sign(DX(isreachable)))=1; updown(2+sign(DY(isreachable)))=1;
if ( (~(leftright(1) && leftright(3)) && ~(updown(1) && updown(3))) || ( any( all(main(corner(1:end-1,:))<0) & main(corner(end,:))>=0 ) ) ) && ~food(13) && main(13)<=0, deletepath=1;
else, deletepath=0; end
DX(far(targetpossible))=DX(newpos(targetpossible));
DY(far(targetpossible))=DY(newpos(targetpossible));

iseeHOME=main>0;
S(iseeHOME)=0; S_ISPATH(iseeHOME)=1; %S_ISCODE(iseeHOME)=1;
iseeFOOD=~main&(food>ants);
S(iseeFOOD)=c+1; S_ISFOOD(iseeFOOD)=1; %S_ISCODE(iseeFOOD)=1;

% path to home ; mark new distance
idx=find(S_ISPATH&isreachable);
if ~isempty(idx), % found path to home
[nill,idxHOME]=min(S(idx)+R(idx)+distances(idx)); idxHOME=idx(idxHOME);
marktarget=min(c-1,S(idxHOME)+1);
else,
idxHOME=[]; marktarget=0;
end
% path to food ; mark it
idx=find(S_ISFOOD&isreachable);
if ~isempty(idx),
[nill,idxFOOD]=max(S(idx)+R(idx)-distances(idx)); idxFOOD=idx(idxFOOD);
if carry || S(idxFOOD)>S(13), if ~marktarget, marktarget=n-1; else, marktarget=marktarget+c-1; end; end; % marks food if found at greater distance than current
else, idxFOOD=[]; end

% move
if carry && ~isempty(idxHOME) && (iseeHOME(idxHOME) || ~scent(13) || ~S(13) || S(idxHOME)<S(13)), dx=DX(idxHOME); dy=DY(idxHOME);       % follow home signal with lowest distance (as long as I am decreasing distances or I see home)
elseif ~carry && ~isempty(idxFOOD) && ~all(S(idx)==c), dx=DX(idxFOOD); dy=DY(idxFOOD);  % follow food signal with highest distance
else,
idx=find(isreachable);
[nill,idxRANDOM]=min(scent(idx)+ants(idx)+R(idx)); dx=DX(idx(idxRANDOM)); dy=DY(idx(idxRANDOM));
end
dx=max(-1,min(1,dx)); dy=max(-1,min(1,dy));

% Scent coding
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if isnan(t), mark=0;
elseif S_ISTIME(13), mark=k;
else,
newfov=fov(:,:,5+3*dx+dy);
idx=find((scent(newfov(:)).*S_ISTIME(newfov(:)))>4);
if isempty(idx) || all(newfov(idx)==13), mark=4+mod(t-scent(13)-4,k);
elseif deletepath, mark=4+mod(t+(2*c+1)-scent(13)-4,k);
elseif t==4 || ~marktarget, if scent(13), mark=k; else, mark=0; end
else, mark=4+mod(t+marktarget-scent(13)-4,k); end;
end```