Skip to content

Python implementation of Conway's game of life algorithm

License

Notifications You must be signed in to change notification settings

hnrkcode/game-of-life

Repository files navigation

Game of life

Python implementation of Conway's game of life algorithm

made-with-pygame License: MIT Generic badge

Demonstration of game of life

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

Pipenv makes it easier to keep track of which top-level dependencies have been installed and which are only dev dependencies. Commands inside pipenv can be run with pipenv run before the commands.

python -m venv venv
source venv/bin/activate
pip install pipenv
pipenv install --dev

Create requirements.txt file from pipenv:

pipenv run pip freeze > requirements.txt

Run the game:

python run.py

Usage

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

Tests

Run all tests.

pytest -v tests/ --cov=gameoflife/

About

Python implementation of Conway's game of life algorithm

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages