uchicago.src.repastdemos.life
Class LifeSpace

java.lang.Object
  extended by uchicago.src.repastdemos.life.LifeSpace
All Implemented Interfaces:
Space

public class LifeSpace
extends java.lang.Object
implements Space

A grid space for LifeAgents. Agents inhabit the grid cells. This class is responsible for creating new LifeAgents in those cells that have 3 and only 3 LifeAgents for neighbors. This is a bounded grid, that is optionally toriodal.


Constructor Summary
LifeSpace(int xSize, int ySize, boolean toriodal, LifeModel model)
          Creates this LifeSpace of the specified width (xSize) and height (ySize).
 
Method Summary
 void addAgent(LifeAgent agent)
          Adds the agent at its coordinates.
 Displayable getDisplay()
          Returns the Displayable appropriate for this space.
 int getNumNeighbors(int x, int y)
          Returns the number of LifeAgents around the x, y coordinate.
 int getXSize()
          Returns the width of this LifeSpace.
 int getYSize()
          Returns the height of this LifeSpace.
 boolean isEmptyAt(int x, int y)
          Returns true if the cell at the specified coordinates is empty.
 void remove(LifeAgent agent)
          Removes an agent from this space.
 void removeAgentAt(int x, int y)
          Removes the agent at the specified coordinates.
 void step(java.util.ArrayList list)
          Iterates through each cell, if the cell is empty and has 3 neighbors then new agent there.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LifeSpace

public LifeSpace(int xSize,
                 int ySize,
                 boolean toriodal,
                 LifeModel model)
Creates this LifeSpace of the specified width (xSize) and height (ySize).

Method Detail

getXSize

public int getXSize()
Returns the width of this LifeSpace.

Specified by:
getXSize in interface Space

getYSize

public int getYSize()
Returns the height of this LifeSpace.

Specified by:
getYSize in interface Space

remove

public void remove(LifeAgent agent)
Removes an agent from this space. Actual removal is not performed until after all step() methods have completed.

Specified by:
remove in interface Space

removeAgentAt

public void removeAgentAt(int x,
                          int y)
Removes the agent at the specified coordinates. This occurs immediately.

Specified by:
removeAgentAt in interface Space

addAgent

public void addAgent(LifeAgent agent)
Adds the agent at its coordinates.

Specified by:
addAgent in interface Space

getNumNeighbors

public int getNumNeighbors(int x,
                           int y)
Returns the number of LifeAgents around the x, y coordinate. This is a Moore neighborhood.

Specified by:
getNumNeighbors in interface Space

getDisplay

public Displayable getDisplay()
Returns the Displayable appropriate for this space. In this case, this returns an Object2DDisplay.

Specified by:
getDisplay in interface Space

isEmptyAt

public boolean isEmptyAt(int x,
                         int y)
Returns true if the cell at the specified coordinates is empty.

Specified by:
isEmptyAt in interface Space

step

public void step(java.util.ArrayList list)
Iterates through each cell, if the cell is empty and has 3 neighbors then new agent there.

Specified by:
step in interface Space