/** Whenever actors contains more foes than friends, this OpossumCritter plays dead.
* Postcondition: (1) The state of all actors in the grid other than this critter and the
* elements of actors is unchanged. (2) The location of this critter is unchanged.
* @param actors a group of actors to be processed
public void processActors(ArrayList<Actor> actors)
int friends = 0, foes = 0;
for (Actor a : actors)
else if (isFoe(a))
if (foes > friends)
numStepsDead = 0;
- Or use one counter: add 1 for a friend, subtract 1 for a foe.
/** Selects the location for the next move.
* Postcondition: (1) The returned location is an element of locs, this critter's current location,
* or null. (2) The state of all actors is unchanged.
* @param locs the possible locations for the next move
* @return the location that was selected for the next move, or null to indicate
* that this OpossumCritter should be removed from the grid.
public Location selectMoveLocation(ArrayList<Location> locs)
if (numStepsDead == 3)
else if (numStepsDead > 0)
Copyright © 2008 by Skylight Publishing