module Ant
class Ant
attr_accessor :home_x, :home_y
end
end
def calculate_action(client, ant)
if ant.cell.home == client.id
ant.home_x = ant.x
ant.home_y = ant.y
end
if ant.has_food and (ant.cell.home == client.id) DROP_FOOD
elsif ant.has_food
if ant.x < ant.home_x
if ant.direction != :east then TURN_LEFT else GO end
elsif ant.x > ant.home_x
if ant.direction != :west then TURN_LEFT else GO end
elsif ant.y < ant.home_y
if ant.direction != :south then TURN_LEFT else GO end
elsif ant.y > ant.home_y
if ant.direction != :north then TURN_LEFT else GO end
end
elsif (ant.cell.food > 0) and !ant.has_food and (ant.cell.home != client.id) TAKE_FOOD
else case rand(4)
when 0..1 then GO
when 2 then TURN_LEFT
when 3 then TURN_RIGHT
end
end
end