Winner David (Rogue Ant 4)

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

Mighty Ant 3

by Gradiant

Status: Passed
Results: 7848.61 (cyc: 15, node: 718)
CPU Time: 87.0602
Score: 7887.49
Submitted at: 2008-11-08 09:42:15 UTC
Scored at: 2008-11-08 10:45:28 UTC

Current Rank: 71st
Based on: Mighty Ant 2 (diff)
Basis for: Mighty Ant 4 (diff)

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

% 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
	markPerAnt = (max(myScentMap(Y))-myScent-1)/myAntMap(13);
	mark = floor(markPerAnt) + round(rand*mod(markPerAnt, 1));
end
myScentMap(H) = inf;

% fight if challenged
if (any(opAntMap(Y)))
	action = -1;
	dRow = 0;
	dCol = 0;
	if sum(myAntMap(:)) < 8 || rand < 0.5 || 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 < 0.1
		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);
	elseif rand < 0.0 % MB
		opScentMap(mask) = -inf;
		opScentMap(13)   = -inf;
		[r,c] = find(opScentMap==max(opScentMap(:)));
		pick = ceil(rand*numel(r));
		dRow = sign(r(pick)-3);
		dCol = sign(c(pick)-3);
	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

mask = eig(randn(9) + eye(9)); %#ok