Winner David (Rogue Ant 4)

Finish 2008-11-12 12:00:00 UTC

ebi v1

by Jan Langer

Status: Passed
Results: 5280.15 (cyc: 8, node: 406)
CPU Time: 145.397
Score: 6901.13
Submitted at: 2008-11-06 10:07:52 UTC
Scored at: 2008-11-06 13:42:44 UTC

Current Rank: 33rd
Basis for: ebi coward (diff)
Basis for: Don't Like Random (diff)
Basis for: ebiv1 reprise (diff)
...and 3 others.

Comments
Please login or create a profile.
Code
function [dRow,dCol,action,mark] = solver(mainMap,foodMap,myAntMap,opAntMap, ...
                                          myScentMap,opScentMap,myDeathMap,opDeathMap)

% do only 3x3 navigation
mainMap = mainMap(2:4,2:4);
foodMap = foodMap(2:4,2:4);
myAntMap = myAntMap(2:4,2:4);
opAntMap = opAntMap(2:4,2:4);
myScentMap = myScentMap(2:4,2:4);

foodMap(mainMap == 1) = 0; 
myScentMap(mainMap == 1) = 1e20;
mainMap(5) = NaN;

rowIdx = [-1 0 1 -1 0 1 -1 0 1];
colIdx = [-1 -1 -1 0 0 0 1 1 1];

[where,action,mark] = doSolver(mainMap,foodMap,myAntMap,opAntMap,myScentMap);
dRow = rowIdx(where); 
dCol = colIdx(where);

end

function [where,action,mark] = doSolver(mainMap,foodMap,myAntMap,opAntMap,scentMap)

  we = myAntMap(5);

  % mark way back
  [scMax,home] = max(scentMap(:));
  scHere = scentMap(5);
  scDelta = scMax-scHere-20;
  mark = floor(scDelta/we);
  
  % fight
  if any(opAntMap(:))
    action = -1;
    where = 5;
    return;
  end

  % where is home?
  if scMax == 0
    where = wander(mainMap <= 0);
    action = 1;
    return;
  end

  farMap = scentMap<scHere;
  %farMap(5) = 0;

  % set track
  foodHere = foodMap(5); 
  if foodHere > we
    action = 1;
    where = home;
    return;
  end

  % far food in sight
  farFoodMap = foodMap .* farMap;
  %[scentMap myAntMap]
  %mark
  if any(farFoodMap(:))
    [amount,where] = max(farFoodMap(:));
    action = 0;
    return;
  end

  % sit on less food
  if foodHere > 0
    action = 1;
    where = home;
    return;
  end

  % goto near food
  if any(foodMap(:))
    [amount,where] = max(foodMap(:));
    action = 0;
    return;
  end

  % wander around
  sc = scentMap;
  sc(~(mainMap <= 0)) = 1e20;
  
  where = wander(sc < (scHere-200));
  if where < 0
    where = wander(mainMap <= 0);
  end
  action = 0;
  
end

function where = wander(map)
  moves = find(map);
  if numel(moves) > 0
    where = moves(floor (rand*length(moves))+1);
  else
    where = -1;
  end
end