Skip to main content

Python interface for Game of Life

Python wrapper for C implementation of Conway's Game of Life algorithm.

This only provides low-level utilities. It is intended to be used as a dependency for higher-level pure Python packages; as of this update, they are:

life-web-ui Web UI for Conway Game of Life

Installation

Use PyPi package conway-life

python3 -m pip install --upgrade conway-life

Design notes

None of the methods allocate any Python objects; output objects must be created by caller. This both simplifies memory management and makes it possible to avoid unneeded garbage collection for large objects.

API

run(width, height, n_threads, n_iters, pos_start, pos_end, calllback)

width: Width of the board; integer
height: Height of the board; integer
n_threads: Number of worker threads (not yet supported); integer
n_iters: Number of iterations to run; integer
pos_start: Initial position; boolean list of size width x height
pos_end: (Output) Final position; boolean list of size width x height. Must be pre-allocated.
callback: Iteration calllback, or None (see below)

return value: number of actually executed iterations (never more than n_iters, but could be less, see below)

callback(n_iter, count, bhash, pos_ptr, fin)

n_iter: current iteration (see below); integer
count: count of cells; integer
bhash: hash of current position; integer
pos_ptr: internal memory pointer to the current position; integer. Method read_ptr can be used to extract the position
fin: 1 if this is final iteration, 0 if not

return value: None or integer; value 1 will trigger iterations to stop immediately.

Notes

  1. callback (if defined) is called before first iteration, and then again after every iterations, including the last (where fin=1). Therefore, normally callback method is called 1 + n_iters times.

  2. However this method also detects loops and if your sequence deteriorates to a loop, it will cut it short; fin would still be set to 1 on the last iteration only regardless. Hash values used in loop detection is passed to the callback.

read_ptr(width, height, pos_ptr, position)

width: Width of the board; integer
height: Height of the board; integer
pos_ptr: Internal memory pointer returned in a callback (see method run); integer
position: (Output) Intermediary position; boolean list of size width x height. Must be pre-allocated.

return value: 1 on success

Metadata

Release files for conway-life 0.1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for conway-life 0.1.4.1
File Size Uploaded
conway-life-0.1.4.1.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for conway-life 0.1.4.1
File Interpreter ABI Platform
conway_life-0.1.4.1-cp37-cp37m-macosx_11_0_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 11.0+ x86-64 Details

Total release size: 14.7 kB

Release files / conway-life-0.1.4.1.tar.gz

Download URL conway-life-0.1.4.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
754f1cd18880655904cd6b927c6c91eca28edb1c741111ea949c74303b90c420
BLAKE2b-256 checksum
How to use checksums
fa693695bf41f954dd5b3cda2b311df2c0a28d9b9c53e3a12879213a858b5780
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.11

Release files / conway_life-0.1.4.1-cp37-cp37m-macosx_11_0_x86_64.whl

Download URL conway_life-0.1.4.1-cp37-cp37m-macosx_11_0_x86_64.whl
Size 8.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
0809a6ba4d9f4d00fef46acb72b5c513d982a3524fe7f1b8e749d478097206cf
BLAKE2b-256 checksum
How to use checksums
fe39e67e66ee5df11c552980d528330b547bec44c8f8f43f48a939de1df06403
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.11

Release history Release notifications | RSS feed

This release

0.1.4.1 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page