A4Shell
Class WatorWorld

java.lang.Object
  extended by A4Shell.WatorWorld

public class WatorWorld
extends java.lang.Object

Provides a simulation of a Wat-or World as described by A.K. Dewdney in his Scientific American article: Sharks and fish wage an ecological war on the toroidal planet Wa-Tor.


Constructor Summary
WatorWorld(int rows, int cols, int numFish, int numSharks)
          Create a new Watorworld.
 
Method Summary
 java.awt.Color getColor(int row, int col)
          Return the color of the object at the specified cell.
 int getNumCols()
          Get the number of columns in this world.
 int getNumFish()
          Return the number of fish in the simulation.
 int getNumSharks()
          Return the number of sharks in the simulation.
 int getNumSpots()
          Get the total number of cells in this world.
 int numRows()
          Get the number of rows in this world.
 void reset(int numFish, int numSharks)
          Reset the world.
 void step()
          Perform one step of the simulation.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WatorWorld

public WatorWorld(int rows,
                  int cols,
                  int numFish,
                  int numSharks)
Create a new Watorworld. rows and cols must both be greater than 0. numSharks + numFish must be less than or equal to rows * cols.

Parameters:
rows - rows > 0, number of rows in world
cols - cols > 0, number of cols in world
numFish - The number of fish initially
numSharks - The number of sharks initially
Method Detail

reset

public void reset(int numFish,
                  int numSharks)
Reset the world. All old fish and sharks are removed and the world is repoluated with the given numebr of fish and sharks. numSharks + numFish must be less than or equal to getNumSpots(). (The number of rows in the world time sthe number of columns in the world.

Parameters:
numFish - The number of fish to add to the world
numSharks - The number of fish to add to the world

step

public void step()
Perform one step of the simulation.


getNumFish

public int getNumFish()
Return the number of fish in the simulation.

Returns:
The current number of fish in the simulation.

getNumSharks

public int getNumSharks()
Return the number of sharks in the simulation.

Returns:
The current number of sharks in the simulation.

getColor

public java.awt.Color getColor(int row,
                               int col)
Return the color of the object at the specified cell. row must be greater than or equal to 0 and less than numRows() and col must be greater than or equal to 0 and less than numCols().

Parameters:
row - the row value
col - the column value
Returns:
The color of the cell in the simulation. Fish are green, Sharks are orange, open ocean (unoccupied cells) are blue.

numRows

public int numRows()
Get the number of rows in this world.

Returns:
the number of rows in this world.

getNumCols

public int getNumCols()
Get the number of columns in this world.

Returns:
the number of columns in this world.

toString

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

getNumSpots

public int getNumSpots()
Get the total number of cells in this world.

Returns:
The total number of cells in this world.