Winner David (Rogue Ant 4)

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

CCat24

by Sergey Y.

Status: Passed
Results: 8149.05 (cyc: 21, node: 740)
CPU Time: 63.3626
Score: 8167.63
Submitted at: 2008-11-08 08:27:54 UTC
Scored at: 2008-11-08 09:29:32 UTC

Current Rank: 98th
Based on: Queue test 3 (diff)

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

% mask
mask = isnan(mainMap);
if mask(7)
    mask([1 2 6]) = true;
end;
if mask(9)
    mask([4 5 10]) = true;
end;
if mask(17)
    mask([16 21 22]) = true;
end;
if mask(19)
    mask([20 24 25]) = true;
end;
if mask(8)
    mask(3) = true;
end;
if mask(12)
    mask(11) = true;
end;
if mask(14)
    mask(15) = true;
end;
if mask(18)
    mask(23) = true;
end;
mainMap(mask) = nan;

% decide scent
Y = [7 8 9 12 13 14 17 18 19];
myScent = myScentMap(13);

H = mainMap == 1;
mark=100*H(13)+floor((max(myScentMap(Y))-myScent-1)/myAntMap(13))*(~H(13));


myScentMap(H) = inf;

% fight if challenged
if (any(opAntMap(Y)))
    action = -1;
    if (sum(myAntMap(:))<8)||(rand < 0.5)
        dRow = 0;
        dCol = 0;
        return
    else
        [r,c] = find(opAntMap(2:4,2:4)&~opAntMap(4:-1:2,4:-1:2));
        if isempty(r)
            dRow = 0;
            dCol = 0;
            return
        end;
    end;
end;

% look for food
action = 0;
foodMap(H) = 0;
netFood = foodMap-myAntMap;
netFood(mask) = 0;
netFood(H) = 0;
if (foodMap(13) > 0)&&(rand > (myAntMap(13)-foodMap(13))/myAntMap(13))
    lowFood = (netFood>0)&(myScentMap<myScent);
    hiFood = (netFood>0)&(myScentMap>myScent);
    myFood = foodMap(13);
    if ~any(lowFood(:))||((foodMap(13) > 1)&&(rand > sqrt(1/foodMap(13))))
        % carry home
        action = 1;
        myScentMap(mask) = -inf;
        myScentMap(13) = -inf;
        maxScent = max(myScentMap(:));
        if (maxScent == 0)
            mainMap(13) = nan;
            [r,c] = find(~isnan(mainMap(2:4,2:4)));
            pick = ceil(rand*numel(r));
            dRow = sign(r(pick)-2);
            dCol = sign(c(pick)-2);
        else
            [r,c] = find(myScentMap==maxScent);
            dRow = sign(r(1)-3);
            dCol = sign(c(1)-3);
        end;
    else
        % gather lower
        bottomFood = min(myScentMap(lowFood>0));
        [r,c] = find((lowFood>0)&(myScentMap==bottomFood));
        dRow = sign(r(1)-3);
        dCol = sign(c(1)-3);
    end;
elseif (any(netFood(:) > 0))
    % gather
    bottomFood = min(myScentMap(netFood>0));
    [r,c] = find((netFood>0)&(myScentMap==bottomFood));
    %[r,c] = find(netFood==max(netFood(:)));
    dRow = sign(r(1)-3);
    dCol = sign(c(1)-3);
else
    % explore
    if (rand>.9)
        mainMap(13) = nan;
        [r,c] = find(~isnan(mainMap(2:4,2:4)));
        pick = ceil(rand*numel(r));
        dRow = sign(r(pick)-2);
        dCol = sign(c(pick)-2);
    else
        myScentMap(mask) = inf;
        myScentMap(13) = inf;
        [r,c] = find(myScentMap==min(myScentMap(:)));
        pick = ceil(rand*numel(r));
        dRow = sign(r(pick)-3);
        dCol = sign(c(pick)-3);
    end;
end;
end