import java.util.*; class Ant { private Point p, nest; private Environment env; private boolean carriesFood; private int lifespan; public Ant(Point p, Point nest, Environment env) { lifespan = 30; carriesFood = false; this.p = p; this.nest = nest; this.env = env; } public void behave() { System.out.println("I'm behaving...."); if (lifespan > 0) { if (carriesFood) { p = p.stepInDirection(nest); System.out.println("I'm heading to the nest at " + nest); } else { List neighbours = p.neighbours(); Random rand = new Random(); p = neighbours.get(rand.nextInt(neighbours.size())); System.out.println("I moved to " + p); } lifespan--; if (lifespan == 0) { env.dropFood(p); System.out.println("I died at " + p); } else { if (p.equals(nest) && carriesFood) { // drop the food } else { // pick the food if it we are out of the nest } } } } }