Skip to main content

Python library for simulating Conway's Game of Life

Project description

A Python library for Conway's Game of Life

This framework allows you to create and simulate various artificial lifeforms and cellular automata easily: simply define your board, add your lifeforms, and execute the run command! It also provides a myriad of pre-made lifeforms while allowing you to create your own.

Why name it Seagull? Conway's Game of Life is quite a mouthful, so I just refer to its acronym, CGoL. The word "seagull" is just a pun of that.

Simulate your first lifeforms in few lines of code:

import seagull as sg
from seagull.lifeforms import Pulsar

# Initialize board
board = sg.Board(size=(19,60))  

# Add three Pulsar lifeforms in various locations
board.add(Pulsar(), loc=(1,1))
board.add(Pulsar(), loc=(1,22))
board.add(Pulsar(), loc=(1,42))

# Simulate board
sim = sg.Simulator(board)      
sim.run(sg.rules.conway_classic, iters=1000)

Optionally, you can animate the simulation by running sim.animate():

Aside from Pulsar, we have a nice collection of lifeforms for you to choose from!

Installation

To install Seagull, run this command in your terminal:

pip install pyseagull

This is the preferred method to install Seagull, as it will always install the most recent stable release.

In case you want to install the bleeding-edge version, clone this repo:

git clone https://github.com/ljvmiranda921/seagull.git

and then run

cd seagull
python setup.py install

Usage

There are three main components for an artificial life simulation:

  • The Board or the environment in which the lifeforms will move around
  • The Lifeform that will interact with the environment, and
  • The rules that dictate if a particular cell will survive or not

In Seagull, you simply define your Board, add your Lifeform/s, and run the Simulator given a rule. You can add multiple lifeforms as you want:

import seagull as sg
from seagull import lifeforms as lf

board = sg.Board(size=(30,30))
board.add(lf.Blinker(length=3), loc=(4,4))
board.add(lf.Glider(), loc=(10,4))
board.add(lf.Glider(), loc=(15,4))
board.add(lf.Pulsar(), loc=(5,12))
board.view()  # View the current state of the board

Then you can simply run the simulation, and animate it when needed:

sim = sg.Simulator(board)
hist = sim.run(sg.rules.conway_classic, iters=1000)  # Save simulation history
sim.animate()

Adding custom lifeforms

You can manually create your lifeforms by using the Custom class:

import seagull as sg
from seagull.lifeforms import Custom

board = sg.Board(size=(30,30))
board.add(Custom([[0,1,1,0], [0,0,1,1]]), loc=(0,0))

Obtaining simulation statistics and history

By default, the simulation statistics will always be returned after calling the run() method. In addition, you can also obtain the history by calling the get_history() method.

# The run() command returns the run statistics
stats = sim.run(sg.rules.conway_classic, iters=1000)
# You can also get it using get_history()
hist = sim.get_history()

Examples

You can find more examples in the documentation

Contributing

This project is open for contributors! Contibutions can come in the form of feature requests, bug fixes, documentation, tutorials and the like! We highly recommend to file an Issue first before submitting a Pull Request.

Simply fork this repository and make a Pull Request! We'd definitely appreciate:

  • Implementation of new features
  • Bug Reports
  • Documentation
  • Testing

License

MIT License (c) 2019, Lester James V. Miranda

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

pyseagull-1.0.0b4.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

pyseagull-1.0.0b4-py2.py3-none-any.whl (19.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyseagull-1.0.0b4.tar.gz.

File metadata

  • Download URL: pyseagull-1.0.0b4.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pyseagull-1.0.0b4.tar.gz
Algorithm Hash digest
SHA256 727993d2b4e3971a3e2c9ff699f81a93c199855e51f71eb78b1f9553da48a642
MD5 78a8d22fc476b9a52d87a8ccc95f6b93
BLAKE2b-256 8ada4945856e1b5b22784279b9631fa008d9251a37745b59854aa025a1bee8cf

See more details on using hashes here.

File details

Details for the file pyseagull-1.0.0b4-py2.py3-none-any.whl.

File metadata

  • Download URL: pyseagull-1.0.0b4-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pyseagull-1.0.0b4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ecaaf4f99236267b326d81f9a701cd1b36e14c61674a2dc92ab6b5e7a79b895b
MD5 75b34592122789f2d284de408765da7b
BLAKE2b-256 74804f51f4b8176d2606319dc64ca26db5656fee990b177434d5d76552d71145

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page