Python interface for game of life
Project description
Python interface for Game of Life
Python wrapper for C implementation of Conway's Game of Life algorithm.
This only provides low-level utilities.
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
-
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 called1 + n_iters
times. -
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for conway_life-0.1.4-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9c2a7bd9968e2eb038492c9710f08f99f40e8fc1994a17a751d45db6b6685a5 |
|
MD5 | d85f2f5207a028d7d6f3833f9a9075ba |
|
BLAKE2b-256 | a79b0645b1320bbe66e08f3d224e8f4bc5790f14a9d290da3428f6212c792a69 |