Simulate Conway's Game of Live in Python.
Repository by Felix Fehse (shiMusa)
┌────────────────────────────────────────────────────────────────┐
│ ▄▀ ██▀ ▄ ▄█▀▄█▀▄ █▀ ▄▀▄ ▄▄ ▀ ▀▀ ▀ █ ▀ █│
│ ▀ ▄█▀ ▄ ▄▄ ▀ █ █ ▀█▀ ▀▀ ▄▀█▄ │
│▄ ▄ ▀█▄▀ ▀ ▀▀ ▀█▄▀ ▀▄ ▄ ▄ ▄▄▄▄▄██▀█ ▄▀│
│ ▄▄▀ ▄█▄ ██ ▀▀ ▄▄ ▀▀ ▀▀▄ ███ ▀█ ▄▄█ ▀▄ │
│▀▀█ ▄█▀▀▀ ▀ █▄▀█ ▀▀ ▀▀ ▀▀ ▄ ▄ ▀ ▄ ▀█│
│█▀ ▀█ ▀▀ ▄▄▀ ▄ ▀▄ ▄ ▄ ▀▄▄ ▀▄█▄▀█▀ ▄▄▀│
│ ▀▄▄█ █▀ ▄█▄ ▀▄ █ ▀ ▄ █▄ ▄▄ ▀▀▄▄ █▀▀│
│ ▄▄█▄ ▀▄ ▀▄█▄▄▀ █▀ █ ▄█ ▀ ▀▄█▀█ ▄█▄ ▀█ │
│ ▀█ ██ ▄ ▄▀ ▀▀ ▀ ▀▄▀ ▀█▄ ▀▀ ▄▄██▀▀▀▀ ▀▄ │
│ ▀ ▄▀▄ █ ▀ ▄▀▀█ ▀ ▀▄▄▄▀│
│ ▄ █ █▄ ▄ ▄ ▀ ▄ │
│ ▄ ▄ ▄ ▀▄▄ █▀▀ ▀███▄ ▄ ▄ │
│ ▀ ▀▀▄ ▀ ▄ ▄ █ ▄▀▀ ▄▄ ██│
│██▀▀▀█▄ █ ▀▄ ██ ▀▄ ██▄ ▄█ ▄█ ▀▀│
│▀▀ ▄▄▀▄ █ ▄ ▀▄████▄ ▀█▄▄ ▀█ █▄▄▄▄▄▄▄▄ █▀▀│
│ █ █▄██ ▄▀▀ ▄ ▀ █ ▀▄▄ ▀ ▀▀ ▀▄ ▄ █ █ ▀█▄ │
└────────────────────────────────────────────────────────────────┘
The game can either be printed in the console/terminal, or rendered to a native window using pyray/raylib.
Example use is given below, the interactive html documentation can be found under docs/index.html.
If not already installed, install uv for your system.
Install dependencies via
uv syncUsing Docker
Warning
You might not be able to use the raylib native window renderin using Docker!
Build Docker image via
docker build -t conway .Run Docker image and access bash shell
docker run -it conway /bin/bashThe provided main.py program will randomly generate an initial state of the game and simulate it's evolution.
For the first time, it's suggested to run with the following arguments:
uv run main.py --grid 64 32 --sleep-ms 500 --max-iter 10It will
-g 64 321: generate a game with 64x32 cells,-s 500: sleep between iteration for 500 ms,-i 10: run for 10 iterations and then stop.
You can get help on the commands via
uv run main.py --helpYou can use the Raylib rendering with the flag --raylib, e.g.
uv run main.py --grid 256 256 --sleep-ms 32 --max-iter 1000 --raylibThe module conway can be fund under src/conway/, the tests are under tests/.
These are the typical development commands used:
black: python source code formatter, run via
uv run black .or on windows from scripts/ via the bat-script black.
mypy: python typing tests, run via
uv run uv run mypy -p conway -p tests
uv run mypy main.pyor on windows from scripts/ via the bat-script mypy.
pytest: python testing harness, run via
uv run pytestor on windows from scripts/ via the bat-script test.
pdoc: python documentation tool, rendering the project and it's docstrings into interactive html documents. Run with auto updates via
uv run pdoc src/conway --docformat googleor on windows from scripts/ via the bat-script doc.
To build the documentation to the docs/ folder, run via
uv run pdoc src/conway --docformat google -o ./docs