Winner David (Rogue Ant 4)

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

Unplanned Darkness 7

by Alan Chalker

Status: Passed
Results: 8149.05 (cyc: 14, node: 630)
CPU Time: 63.9087
Score: 8160.77
Submitted at: 2008-11-08 01:41:42 UTC
Scored at: 2008-11-08 01:43:14 UTC

Current Rank: 85th

Comments
Alan Chalker
08 Nov 2008
Lets see how this works
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);
K = [7 7 7 9 9  9 17 17 17 19 19 19 8 12 14 18];
L = [1 2 6 4 5 10 16 21 22 20 24 25 3 11 15 23];
mask(L(mask(K))) = true;
mainMap(mask) = nan;

% decide scent
Y = [7 8 9 12 13 14 17 18 19];
myScent = myScentMap(13);
H = mainMap == 1;
if H(13)
    mark = 100;
else
    mark = floor((max(myScentMap(Y))-myScent-1)/myAntMap(13));
end
myScentMap(H) = inf;

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

% look for food
action = 0;
foodMap(H) = 0;
netFood = foodMap-myAntMap;
netFood(mask|H) = 0;
netFoodPositive = netFood > 0;
myFood = foodMap(13);
if (myFood > 0)&&(rand > (myAntMap(13)-myFood)/myAntMap(13))
    lowFood = netFoodPositive&(myScentMap<myScent);
    if ~any(lowFood(:))||((myFood > 1)&&(rand > sqrt(1/myFood)))
        % 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
        lowFoodPositive = lowFood > 0;
        [r,c] = find(lowFoodPositive&(myScentMap==min(myScentMap(lowFoodPositive))));
        dRow = sign(r(1)-3);
        dCol = sign(c(1)-3);
    end
elseif any(netFood(:) > 0)
    % gather
    [r,c] = find(netFoodPositive&(myScentMap==min(myScentMap(netFoodPositive))));
    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