Class ConwayLife

java.lang.Object
org.episteme.natural.computing.ai.automata.ConwayLife
All Implemented Interfaces:
CellularAutomaton<Boolean>

public class ConwayLife extends Object implements 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 Details

    • ConwayLife

      public ConwayLife(int width, int height)
  • Method Details

    • nextGeneration

      public void nextGeneration()
      Description copied from interface: CellularAutomaton
      Advances the automaton by one generation.
      Specified by:
      nextGeneration in interface CellularAutomaton<Boolean>
    • getState

      public Boolean getState(int x, int y)
      Description copied from interface: CellularAutomaton
      Gets the state of the cell at the specified coordinates.
      Specified by:
      getState in interface CellularAutomaton<Boolean>
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the state at (x, y)
    • setState

      public void setState(int x, int y, Boolean state)
      Description copied from interface: CellularAutomaton
      Sets the state of the cell at the specified coordinates.
      Specified by:
      setState in interface CellularAutomaton<Boolean>
      Parameters:
      x - the x coordinate
      y - the y coordinate
      state - the new state
    • getWidth

      public int getWidth()
      Description copied from interface: CellularAutomaton
      Gets the width of the grid.
      Specified by:
      getWidth in interface CellularAutomaton<Boolean>
      Returns:
      grid width
    • getHeight

      public int getHeight()
      Description copied from interface: CellularAutomaton
      Gets the height of the grid.
      Specified by:
      getHeight in interface CellularAutomaton<Boolean>
      Returns:
      grid height
    • getGeneration

      public long getGeneration()
      Description copied from interface: CellularAutomaton
      Returns the current generation number.
      Specified by:
      getGeneration in interface CellularAutomaton<Boolean>
      Returns:
      generation count
    • reset

      public void reset()
      Description copied from interface: CellularAutomaton
      Resets the automaton to initial state.
      Specified by:
      reset in interface CellularAutomaton<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