org.drools.examples.conway
Class CellGrid

java.lang.Object
  extended by org.drools.examples.conway.CellGrid

public class CellGrid
extends java.lang.Object

A CellGrid represents a grid of Cell objects.

See Also:
Cell
 

Constructor Summary
CellGrid(int rows, int columns)
          Constructs a CellGrid
 
Method Summary
 Cell getCellAt(int row, int column)
           
 int getNumberOfColumns()
           
 int getNumberOfLiveCells()
           
 int getNumberOfRows()
           
 void killAll()
          kills all cells in the grid
 boolean nextGeneration()
          Moves this grid to its next generation
 void setPattern(ConwayPattern pattern)
          Populates the grid with a ConwayPattern
 boolean transitionState()
          Transitions this grid to its next state of evolution
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CellGrid

public CellGrid(int rows,
                int columns)
Constructs a CellGrid

Parameters:
rows - number of rows in the grid
columns - number of columns in the grid
Method Detail

getCellAt

public Cell getCellAt(int row,
                      int column)
Parameters:
row - row of the requested cell
column - column of the requested cell
Returns:
the cell at the specified coordinates
See Also:
Cell

getNumberOfRows

public int getNumberOfRows()
Returns:
the number of rows in this grid
See Also:
CellGrid.getNumberOfColumns()

getNumberOfColumns

public int getNumberOfColumns()
Returns:
the number of columns in this grid
See Also:
CellGrid.getNumberOfRows()

nextGeneration

public boolean nextGeneration()
Moves this grid to its next generation

Returns:
true if the state changed, otherwise false
See Also:
CellGrid.transitionState()

getNumberOfLiveCells

public int getNumberOfLiveCells()
Returns:
the number of cells in the grid that are alive
See Also:
CellState

killAll

public void killAll()
kills all cells in the grid


transitionState

public boolean transitionState()
Transitions this grid to its next state of evolution

Returns:
true if the state changed, otherwise false
See Also:
CellGrid.nextGeneration()

setPattern

public void setPattern(ConwayPattern pattern)
Populates the grid with a ConwayPattern

Parameters:
pattern - pattern to populate the grid with
See Also:
ConwayPattern