cs2110.assignment5
Class Naturalist

java.lang.Object
  extended by cs2110.assignment5.Naturalist
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
RandomWalkNaturalist

public abstract class Naturalist
extends java.lang.Object
implements java.lang.Runnable

Abstract naturalist class. To implement a naturalist AI, extend this class and implement the run method.

Author:
cs2110 staff

Field Summary
static int MAX_ANIMAL_CAPACITY
          Maximum number of animals that can be carried at a time
 
Constructor Summary
Naturalist()
          Default constructor for the naturalist.
 
Method Summary
 void collect(java.lang.String name)
          Collect an animal from the current location.
 void dropAll()
          Drop all animals currently being carried.
 Node[] getExits()
          Return an array of Nodes that the naturalist can move to from the current location.
 java.util.Collection<java.lang.String> getInventory()
          Return a the names of animals being carried by the naturalist
 Node getLocation()
          Return the current graph node occupied by this thing
 int getNodeCount()
          The number of nodes in this map.
 java.util.Random getRandom()
          Returns a random number generator that has been initialized with the game world's default seed.
 java.util.Collection<java.lang.String> listAnimalsPresent()
          List the animals present at the current location.
 void moveTo(Node destination)
          Move to an adjacent node.
abstract  void run()
          Called by the simulator to run the naturalist program.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_ANIMAL_CAPACITY

public static final int MAX_ANIMAL_CAPACITY
Maximum number of animals that can be carried at a time

See Also:
Constant Field Values
Constructor Detail

Naturalist

public Naturalist()
Default constructor for the naturalist. Warning: When the constructor is called, the world map has not been initialized. Calls to getLocation() will return null.

Method Detail

run

public abstract void run()
Called by the simulator to run the naturalist program.

Specified by:
run in interface java.lang.Runnable

getLocation

public Node getLocation()
Return the current graph node occupied by this thing

Returns:
The naturalist's current location.

getRandom

public java.util.Random getRandom()
Returns a random number generator that has been initialized with the game world's default seed. Use this if you need to generate pseudo-random numbers; it will return consistent results for the random seed given on the command line.

Returns:

getExits

public Node[] getExits()
Return an array of Nodes that the naturalist can move to from the current location.

Returns:
An array of adjacent nodes that are not blocked by water or trees.

moveTo

public void moveTo(Node destination)
            throws IllegalMoveException
Move to an adjacent node. If location is the current location, does nothing. Does nothing if destination is the current location.

Parameters:
destination - An adjacent node
Throws:
IllegalMoveException - Thrown if location is not adjacent, or is blocked by water or trees.

listAnimalsPresent

public java.util.Collection<java.lang.String> listAnimalsPresent()
List the animals present at the current location.

Returns:
The names of animals present at the current location, as a collection of Strings

collect

public void collect(java.lang.String name)
             throws CapacityExceededException,
                    SpecimenNotFoundException
Collect an animal from the current location.

Parameters:
name -
Throws:
CapacityExceededException - Thrown if already carrying the maximum number of animals, as given by getCapacity().
SpecimenNotFoundException - Thrown if the named animal is not present.

dropAll

public void dropAll()
Drop all animals currently being carried. If the current location is the ship, animals will disappear and score will be increased.


getNodeCount

public final int getNodeCount()
The number of nodes in this map. Note that some nodes may be obstacles, hence unreachable.

Returns:

getInventory

public final java.util.Collection<java.lang.String> getInventory()
Return a the names of animals being carried by the naturalist

Returns:
A collection of Strings

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object