gridWorldTest
Class CrabCritter

java.lang.Object
  extended by info.gridworld.actor.Actor
      extended by info.gridworld.actor.Critter
          extended by gridWorldTest.CrabCritter

public class CrabCritter
extends Critter

A CrabCritter looks at a limited set of neighbors when it eats and moves.
This class is not tested on the AP CS A and AB exams.


Constructor Summary
CrabCritter()
           
 
Method Summary
 java.util.ArrayList<Actor> getActors()
          A crab gets the actors in the three locations immediately in front, to its front-right and to its front-left
 java.util.ArrayList<Location> getLocationsInDirections(int[] directions)
          Finds the valid adjacent locations of this critter in different directions.
 java.util.ArrayList<Location> getMoveLocations()
          Gets a list of possible locations for the next move.
 void makeMove(Location loc)
          If the crab critter doesn't move, it randomly turns left or right.
 
Methods inherited from class info.gridworld.actor.Critter
act, processActors, selectMoveLocation
 
Methods inherited from class info.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

CrabCritter

public CrabCritter()
Method Detail

getActors

public java.util.ArrayList<Actor> getActors()
A crab gets the actors in the three locations immediately in front, to its front-right and to its front-left

Overrides:
getActors in class Critter
Returns:
a list of actors occupying these locations

getMoveLocations

public java.util.ArrayList<Location> getMoveLocations()
Description copied from class: Critter
Gets a list of possible locations for the next move. These locations must be valid in the grid of this critter. Implemented to return the empty neighboring locations. Override this method in subclasses to look elsewhere for move locations.
Postcondition: The state of all actors is unchanged.

Overrides:
getMoveLocations in class Critter
Returns:
list of empty locations immediately to the right and to the left

makeMove

public void makeMove(Location loc)
If the crab critter doesn't move, it randomly turns left or right.

Overrides:
makeMove in class Critter
Parameters:
loc - the location to move to

getLocationsInDirections

public java.util.ArrayList<Location> getLocationsInDirections(int[] directions)
Finds the valid adjacent locations of this critter in different directions.

Parameters:
directions - - an array of directions (which are relative to the current direction)
Returns:
a set of valid locations that are neighbors of the current location in the given directions