WatorWorld
Class WatorWorld

java.lang.Object
  extended by WatorWorld.WatorWorld

public class WatorWorld
extends 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, double fractionFish, double fractionSharks)
          Create a new Watorworld.
 
Method Summary
 Color getColor(int row, int col)
          Return the color of the Actor 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 getNumRows()
          Get the number of rows in this world.
 int getNumSharks()
          Return the number of sharks in the simulation.
 int getNumSpots()
          Get the total number of cells in this world.
static Color getOceanColor()
           
 void reset(double fractionFish, double fractionSharks)
          Reset the world.
 void step()
          Perform one step of the simulation.
 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,
                  double fractionFish,
                  double fractionSharks)
Create a new Watorworld. rows and cols must both be greater than 0. If fractionFish + fractionSharks > 1 the percentages are scaled down.

Parameters:
rows - rows > 0, number of rows in world
cols - cols > 0, number of cols in world
fractionFish - The fraction of the world initially populated by Fish.
fractionSharks - The fraction of the world initially populated by Sharks.
Method Detail

getOceanColor

public static Color getOceanColor()

reset

public void reset(double fractionFish,
                  double fractionSharks)
Reset the world. All old fish and sharks are removed and the world is repoluated with the given percentages of fish and sharks. If fractionFish + fractionSharks > 1 the fractions are scaled down.

Parameters:
fractionFish - The fraction of the world initially populated by Fish.
fractionSharks - The fraction of the world initially populated by Sharks.

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 Color getColor(int row,
                      int col)
Return the color of the Actor 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. open ocean (unoccupied cells) are blue.

getNumRows

public int getNumRows()
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 String toString()
Overrides:
toString in class Object

getNumSpots

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

Returns:
The total number of cells in this world.