Class ConwayLife
java.lang.Object
org.episteme.natural.computing.ai.automata.ConwayLife
- All Implemented Interfaces:
CellularAutomaton<Boolean>
Conway's Game of Life Implementation.
A cellular automaton devised by mathematician John Conway in 1970. The universe is an infinite two-dimensional grid of cells, each in one of two states (alive or dead). Cells evolve according to simple rules:
- Any live cell with 2 or 3 neighbors survives
- Any dead cell with exactly 3 neighbors becomes alive
- All other cells die or stay dead
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the current generation number.intGets the height of the grid.intReturns the count of live cells.getState(int x, int y) Gets the state of the cell at the specified coordinates.intgetWidth()Gets the width of the grid.voidAdvances the automaton by one generation.voidrandomize(double density) Populates the grid randomly with a given density of live cells.voidreset()Resets the automaton to initial state.voidSets the state of the cell at the specified coordinates.
-
Constructor Details
-
ConwayLife
public ConwayLife(int width, int height)
-
-
Method Details
-
nextGeneration
public void nextGeneration()Description copied from interface:CellularAutomatonAdvances the automaton by one generation.- Specified by:
nextGenerationin interfaceCellularAutomaton<Boolean>
-
getState
Description copied from interface:CellularAutomatonGets the state of the cell at the specified coordinates.- Specified by:
getStatein interfaceCellularAutomaton<Boolean>- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- the state at (x, y)
-
setState
Description copied from interface:CellularAutomatonSets the state of the cell at the specified coordinates.- Specified by:
setStatein interfaceCellularAutomaton<Boolean>- Parameters:
x- the x coordinatey- the y coordinatestate- the new state
-
getWidth
public int getWidth()Description copied from interface:CellularAutomatonGets the width of the grid.- Specified by:
getWidthin interfaceCellularAutomaton<Boolean>- Returns:
- grid width
-
getHeight
public int getHeight()Description copied from interface:CellularAutomatonGets the height of the grid.- Specified by:
getHeightin interfaceCellularAutomaton<Boolean>- Returns:
- grid height
-
getGeneration
public long getGeneration()Description copied from interface:CellularAutomatonReturns the current generation number.- Specified by:
getGenerationin interfaceCellularAutomaton<Boolean>- Returns:
- generation count
-
reset
public void reset()Description copied from interface:CellularAutomatonResets the automaton to initial state.- Specified by:
resetin interfaceCellularAutomaton<Boolean>
-
randomize
public void randomize(double density) Populates the grid randomly with a given density of live cells.- Parameters:
density- probability (0.0-1.0) of each cell being alive
-
getPopulation
public int getPopulation()Returns the count of live cells.- Returns:
- number of alive cells
-