Game of Life
Level: AdvancedConcepts: State Algorithms
Implement Conway's Game of Life, a cellular automaton that simulates the evolution of a population of cells based on simple rules. The game is played on a grid of cells, where each cell can be either alive or dead.
Rules
The rules of the game are:
- Any live cell with fewer than two live neighbors dies (underpopulation)
- Any live cell with two or three live neighbors lives on to the next generation
- Any live cell with more than three live neighbors dies (overpopulation)
- Any dead cell with exactly three live neighbors becomes a live cell (reproduction)
Requirements
- Create a grid of cells that can be initialized with a specific pattern
- Implement the rules to calculate the next generation
- Handle edge cases (cells at the boundaries of the grid)
- Support different grid sizes
- Provide a way to visualize the current state of the grid
Hint
Start by implementing the core rules for a single cell, then expand to handle the entire grid. Consider using a two-dimensional array or a more sophisticated data structure to represent the grid. Think about how to handle the edges of the grid - you could either wrap around (toroidal) or consider cells outside the grid as dead.
Bonus
- Implement different initial patterns (glider, blinker, etc.)
- Add the ability to save and load patterns
- Implement a graphical interface to visualize the evolution
- Add the ability to pause and resume the simulation
- Implement different rule variations (e.g., High Life, Day & Night)