ants
Class AntWorld

java.lang.Object
  extended by ants.AntWorld

public class AntWorld
extends java.lang.Object

The model for the ant simulation
Contains the field (2-D array) in which Ants and DoodleBugs live

Class Invariant: Nr of rows and columns in the gird are positive and do not change once initialized


Constructor Summary
AntWorld(int nrAnts, int nrBugs)
          Construct an AntWorld with a size x size 2-D array containing nrAnts and nrBugs.
 
Method Summary
 Critter getAt(int row, int column)
          Accessor for a cell in the field; required by AntGUI
 int getStepNr()
          Accessor for step number; required by AntGUI
 void simulateOneStep()
          Execute one time step of the simulation; called from AntGUI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AntWorld

public AntWorld(int nrAnts,
                int nrBugs)
Construct an AntWorld with a size x size 2-D array containing nrAnts and nrBugs.

Preconditions: (Guaranteed by the GUI)
1. nrAnts and nrBugs are not negative
2. The total number of ants + bugs does not exceed the number of cells in the 2-D array (rows * columns).

PostCondition: Critter array is created and populated; instance variables initialized

Parameters:
nrAnts - - the initial number of Ants
nrBugs - - the initial number of DoodleBugs
Method Detail

getStepNr

public int getStepNr()
Accessor for step number; required by AntGUI

Returns:
- the current step of the simulation

getAt

public Critter getAt(int row,
                     int column)
Accessor for a cell in the field; required by AntGUI

Precondition: the row and column are valid for the field

Parameters:
row - - the row coordinate of the cell to be accessed
column - - the column coordinate of the row to be accessed
Returns:
- the Critter found at the specified cell

simulateOneStep

public void simulateOneStep()
Execute one time step of the simulation; called from AntGUI

Precondition: the world has been initialized

Postcondition: Executes one step of the simulation by
a. Moving all the critters
b. Adding new critters (breeding)
c. Removing critters that have starved