Python implementation of Conway's game of life algorithm
Game of life is an algorithm invented by John Horton Conway in 1970. The game of life is set on a 2-dimensional grid made up by many small cells. Each cells is in one of two states, alive or dead. A cells state is decided by the algorithm, which has four simple rules:
- A cell dies if it has less than two living neighbors.
- A cell survives until the next generation if it has two or three neighbors.
- A cell with more than three neighbors dies.
- A dead cell with exactly three neighbors turns into a living cell.
This project uses uv for fast Python dependency management. All dependencies are defined in pyproject.toml.
-
Create and activate a virtual environment (if not already active):
uv venv source .venv/bin/activate(The
.venvfolder is created by default.) -
Install all dependencies (including dev dependencies):
uv sync --all-groups
-
Run the game:
make start
When adding new features and fixing bugs do it with a new branch and create a pull request because the changes will be automatically be included in the changelog in the next release. Other changes like refactoring and formatting can be done on the master branch.
Make sure bump-my-version is installed to use the release command, that will automatically bump the version, create a git tag and push it to GitHub were GitHub actions will create a new release and publish the game on itch.io.
There is a pre-commit hook that will only allow you to bump the version with bump-my-version if there are no lint, formatting, type checking or test errors.
make release| key | description |
|---|---|
P |
Pause algorithm |
R |
Remove all cells from the board |
F11 |
Toggle on/off fullscreen |
ESC |
Quit program |
Enter |
Run algorithm |
LEFT MOUSE BUTTON |
Click or hold to draw new cells |
RIGHT MOUSE BUTTON |
Click or hold to erase cells |
UP, DOWN or SCROLL WHEEL |
Choose pattern from predefined patterns |
Hold CTRL + click LEFT MOUSE BUTTON |
Paste chosen pattern onto the grid |
CTRL + Q |
Rotate pattern 90° counter-clockwise |
CTRL + E |
Rotate pattern 90° clockwise |
CTRL + W |
Flip pattern vertically |
CTRL + S |
Flip pattern horizontally |
The following commands are available for development tasks:
| Command | Description |
|---|---|
make start |
Run the game |
make test |
Run all pytests with coverage |
make lint |
Lint code with Ruff |
make format |
Format code with Ruff |
make typecheck |
Type check code with Ty |
This project is licensed under the MIT License. See the LICENSE file for details.
