https://github.com/hnrkcode/game-of-life
Python implementation of Conway's game of life algorithm
https://github.com/hnrkcode/game-of-life
cellular-automaton conways-game-of-life game-of-life pygame python
Last synced: about 2 months ago
JSON representation
Python implementation of Conway's game of life algorithm
- Host: GitHub
- URL: https://github.com/hnrkcode/game-of-life
- Owner: hnrkcode
- License: mit
- Created: 2018-12-03T21:24:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2026-03-30T21:40:35.000Z (2 months ago)
- Last Synced: 2026-03-30T23:38:15.318Z (2 months ago)
- Topics: cellular-automaton, conways-game-of-life, game-of-life, pygame, python
- Language: Python
- Size: 15.1 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Game of life
[](https://www.python.org/downloads/)
[](https://github.com/pygame/pygame)
[](https://github.com/astral-sh/uv)
[](https://github.com/astral-sh/ruff)
[](https://github.com/astral-sh/ty)
[](https://codecov.io/github/hnrkcode/game-of-life)
[](https://opensource.org/licenses/MIT)
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:
1. A cell dies if it has less than two living neighbors.
2. A cell survives until the next generation if it has two or three neighbors.
3. A cell with more than three neighbors dies.
4. A dead cell with exactly three neighbors turns into a living cell.
## Setup
This project uses [uv](https://github.com/astral-sh/uv) for fast Python dependency management. All dependencies are defined in `pyproject.toml`.
1. Create and activate a virtual environment (if not already active):
```bash
uv venv
source .venv/bin/activate
```
(The `.venv` folder is created by default.)
3. Install all dependencies (including dev dependencies):
```bash
uv sync --all-groups
```
4. Run the game:
```bash
make start
```
## Development
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.
```bash
make release
```
## Controls
| 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 |
## Commands
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 |
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.