// method called each time the simulation updates public boolean act() { int capacity = (int) (0.5 * (parent.getTerrain().getWater())); // A formula to approximate carrying capacity if (parent.getPop(species) > capacity) { energy -= 2; } // select a target for predation Organism prey = pickPrey(); if (prey != null) // hunt the prey only if a target was picked hunt(prey); if (Math.random() * 100 < mobility) // move to an adjacent location randomly (based on mobility) move(); return super.act(); // do general organism actions }