A modern implementation of Conway's Game of Life with interactive features.
Project description
Conway's Game of Life Interactive Simulation
This project provides an interactive simulation of Conway's Game of Life, a well-known cellular automaton, implemented using Python, matplotlib
, and numpy
. It allows users to add initial conditions using predefined patterns (like a Glider, Blinker, or Still Life Block) or to manually click on cells to create custom patterns. Once the grid is set up, the simulation runs according to the rules of Conway's Game of Life.
Table of Contents
- Introduction
- Installation
- How to Run the Program
- Predefined Patterns
- Manual Grid Configuration
- Game of Life Rules
- Boundary Conditions
- How the Code Works
- Acknowledgements
Introduction
Conway's Game of Life is a cellular automaton devised by mathematician John Horton Conway in 1970. It's a zero-player game, meaning that its evolution is determined by its initial state, with no further input required from players. The game takes place on an infinite grid of square cells, but in this implementation, the grid is finite.
Each cell in the grid can be in one of two states:
- Alive (represented by
1
). - Dead (represented by
0
).
The game evolves based on the states of each cell and the number of live neighbors it has.
This project provides:
- An interactive grid where users can toggle cell states.
- Predefined buttons for adding Glider, Blinker, and Still Life Block patterns.
- A Start button to run the simulation after grid setup.
- Real-time visualization of the grid as it evolves according to Conway's rules.
Installation
Prerequisites
- Python 3.x
- Libraries:
numpy
matplotlib
Install Required Packages
To install the required libraries, run the following command:
pip install numpy matplotlib
How to Run the Program
- Clone or Download the Repository to your local machine.
- Navigate to the project directory in your terminal or command prompt.
- Run the program using Python:
python game_of_life.py
-
The program will launch a GUI window displaying the grid.
-
Interact with the grid by clicking on cells to toggle their states.
-
Use the predefined buttons to add patterns to the grid.
-
Click the Start button to begin the simulation.
-
Observe the grid's evolution in real-time.
Predefined Patterns
- Glider: A pattern that moves diagonally down and to the right.
Pattern:
0 1 0
0 0 1
1 1 1
- Blinker: A pattern that oscillates between three states.
Pattern:
Initial state (Horizontal):
0 0 0
1 1 1
0 0 0
Next state (Vertical):
0 1 0
0 1 0
0 1 0
- Still Life Block: A static pattern that remains unchanged.
Pattern:
1 1
1 1
Manual Grid Configuration
You can also manually configure the grid by clicking on individual cells. Each click toggles the cell between alive and dead. This allows you to create custom patterns for your own experiments.
Game of Life Rules
Conway's Game of Life operates under the following simple rules:
- Underpopulation: Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
- Survival: Any live cell with two or three live neighbors lives on to the next generation.
- Overpopulation: Any live cell with more than three live neighbors dies, as if by overpopulation.
- Reproduction: Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
Boundary Conditions
This implementation uses fixed boundary conditions. The grid edges do not wrap around, meaning that cells on the edges of the grid have fewer neighbors.
Boundary Condition Types:
- Fixed: The grid edges do not wrap around. Cells on the edges have fewer neighbors.
- For example, the top-left corner cell will only have 3 neighbors instead of 8.
- No Periodic Boundary: In this simulation, there is no wrapping from one edge to the opposite edge. Cells at the edges have fewer neighbors, and their behavior differs from cells in the center.
How the code works
1. Initialisation
The program initializes a grid of size 50x50 where each cell is set to 0
(dead). The user can either toggle the state of individual cells or use predefined patterns (Glider, Blinker, Block).
2. Interactive Grid
The grid is interactive, allowing users to:
- Toggle cell states between alive and dead by clicking on the grid.
- Insert predefined patterns using buttons.
3. Game Logic (Conway's Rules)
After setting up the grid, the user starts the simulation by clicking the Start button. The grid then evolves over time according to Conway’s rules, which are applied to each cell based on the number of live neighbors.
4. Animation
The simulation is animated using matplotlib.animation
, and the grid is updated in real-time.
5. Termination
The simulation runs for a fixed number of steps (by default, 200). This number can be adjusted within the animate
function.
Acknowledgements
This project was inspired by Conway's Game of Life and various open-source Python visualizations of cellular automata.
- John Horton Conway for devising the Game of Life.
- Matplotlib for the animation library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cellular_automata_game_of_life-1.0.3.tar.gz
.
File metadata
- Download URL: cellular_automata_game_of_life-1.0.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3f8794c6b842ee089e32f4934a9a7d3f25f11fadae3535fc4e4aecfd80105bd |
|
MD5 | 7c71f13f598f7c2bba6bc5d7c248d1a3 |
|
BLAKE2b-256 | e48e78bc65c928a95e0409fa6f5ad1950cbb59fb44e47132c7324c038ff32cd2 |
File details
Details for the file cellular_automata_game_of_life-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: cellular_automata_game_of_life-1.0.3-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efebc856011677840a49a5fb2e407e8a5403b793141560ac94158bc46038bd01 |
|
MD5 | f204d9fe0242c8f13a38f337817688e0 |
|
BLAKE2b-256 | fa3c76cf71e1c84e22974a8a52c22948e2d57466f9fd6f7c0b534aed336c6d4e |