This repository provides a modular and extensible implementation of Conway's Game of Life in Python, featuring:
- Customizable grid size and initial patterns
- Pattern registration and management
- Visualization and animation
- Entropy computation
- Unit tests for all core modules
Conway's Game of Life is a cellular automaton devised by mathematician John Conway. It consists of a grid of cells that evolve through generations according to simple rules based on the states of neighboring cells. This project allows you to simulate, visualize, and analyze the Game of Life with various initial patterns.
- Grid and Cell Classes: Core logic for cell state updates and grid management
- Pattern System: Easily add and use named patterns (e.g., block, blinker, glider, pulsar, Gosper glider gun)
- Visualization: Display and animate the grid using matplotlib
- Entropy Analysis: Track the entropy of the grid over time
- Unit Tests: Comprehensive tests for reliability
- Clone the repository:
git clone https://github.com/Paulchen-git/life.git cd life - (Optional) Create and activate a Python virtual environment using Conda:
conda create -n life_env python=3.10 conda activate life_env
- Install required packages:
conda install numpy matplotlib
You can run a simulation and save an animation as a GIF:
python run_simulation.pyThis will use the default grid size and pattern. You can modify run_simulation.py to select a different pattern or grid size.
Patterns are defined in Patterns.py and registered automatically. Available patterns include:
blockblinkergliderpulsarglider_gun
To start with a specific pattern:
from Grid import Grid
grid = Grid(length=64, width=64, pattern='glider')Or use a custom pattern:
from Patterns import Pattern
custom = Pattern(name='my_pattern', live_cells=[(0,0), (1,1)])
grid = Grid(length=10, width=10, pattern=custom)You can visualize the grid and its evolution using matplotlib. See notebook.ipynb for interactive analysis and entropy tracking.
The compute_entropy function in utils.py computes the entropy of the grid, useful for analyzing the system's evolution.
The grid supports various boundary conditions:
fixed: Cells outside the grid are always dead.periodic: The grid wraps around (toroidal).reflective: Edges reflect the state of the nearest cell.
Run all unit tests with:
python tests.pyTo add a new pattern, define a new class in Patterns.py and decorate it with @register_pattern:
@register_pattern
class MY_PATTERN(Pattern):
name = 'my_pattern'
live_cells = [(0,0), (1,1), (2,2)]Cell.py— Cell logicGrid.py— Grid management and visualizationPatterns.py— Pattern definitions and registrationutils.py— Utility functions (e.g., entropy)run_simulation.py— Example simulation scripttests.py— Unit testsnotebook.ipynb— Interactive analysis