com.collegeboard.gridworld.actor
Class SimpleCritter

java.lang.Object
  extended by com.collegeboard.gridworld.actor.Actor
      extended by com.collegeboard.gridworld.actor.AbstractCritter
          extended by com.collegeboard.gridworld.actor.SimpleCritter

public class SimpleCritter
extends AbstractCritter

A simple critter is a critter with basic implementations of the abstract methods of Critter. It does nothing to its neighbors and then moves to a random empty neighboring location.

copyright© 2005 Cay S. Horstmann (http://horstmann.com)

Author:
Cay Horstmann

Constructor Summary
SimpleCritter()
           
 
Method Summary
 ArrayList<Location> getMoveLocations()
          Get the possible locations for the next move.
 ArrayList<Actor> getNeighbors()
          Get the neighbors for processing.
 void makeMove(Location loc)
          Moves this critter to the given location.
 void processNeighbors(ArrayList<Actor> neighbors)
          Process the critter's neighbors.
 Location selectMoveLocation(ArrayList<Location> locs)
          Selects the location for the next move.
 
Methods inherited from class com.collegeboard.gridworld.actor.AbstractCritter
act
 
Methods inherited from class com.collegeboard.gridworld.actor.Actor
getColor, getDirection, getGrid, getLocation, moveTo, putSelfInGrid, removeSelfFromGrid, setColor, setDirection, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleCritter

public SimpleCritter()
Method Detail

getNeighbors

public ArrayList<Actor> getNeighbors()
Description copied from class: AbstractCritter
Get the neighbors for processing. Implemented to return the actors that occupy neighboring grid locations. Override this method for subclasses that look elsewhere for neighbors.

Specified by:
getNeighbors in class AbstractCritter
Returns:
a list of actors that are neighbors of this critter

processNeighbors

public void processNeighbors(ArrayList<Actor> neighbors)
Description copied from class: AbstractCritter
Process the critter's neighbors. This method is implemented to do nothing. Override it in subclasses that process neighbors, for example by examining or removing them.

Specified by:
processNeighbors in class AbstractCritter
Parameters:
neighbors - the neighbors to be processed

getMoveLocations

public ArrayList<Location> getMoveLocations()
Description copied from class: AbstractCritter
Get the possible locations for the next move. Implemented to return the empty neighboring locations. Override this method for subclasses that look elsewhere for move locations.

Specified by:
getMoveLocations in class AbstractCritter
Returns:
a list of possible locations for the next move

selectMoveLocation

public Location selectMoveLocation(ArrayList<Location> locs)
Description copied from class: AbstractCritter
Selects the location for the next move. Implemented to randomly pick one of the possible locations, or to return the current location if locs has size 0. Override this method for subclasses that have another mechanism for selecting the next move location.

Specified by:
selectMoveLocation in class AbstractCritter
Parameters:
locs - the possible locations for the next move
Returns:
the location that was selected for the next move.

makeMove

public void makeMove(Location loc)
Description copied from class: AbstractCritter
Moves this critter to the given location. Implemented to call moveTo. Override this method for subclasses that want to carry out other actions for moving (for example, turning or leaving traces).

Specified by:
makeMove in class AbstractCritter
Parameters:
loc - the location to move to (must be valid)