- Notifications
You must be signed in to change notification settings - Fork30
A Python Library for Conway's Game of Life
License
ljvmiranda921/seagull
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Python library for Conway's Game of Life
This framework allows you to create and simulate various artificial lifeformsand cellular automata easily: simply define your board, add your lifeforms,and execute therun
command! It also provides a myriad of pre-madelifeforms while allowing you to create your own.
Why name it Seagull? Conway's Game of Life is quite a mouthful, so I just refer toits acronym, CGoL. The word "seagull" is just a pun of that.
Simulate your first lifeforms in few lines of code:
importseagullassgfromseagull.lifeformsimportPulsar# Initialize boardboard=sg.Board(size=(19,60))# Add three Pulsar lifeforms in various locationsboard.add(Pulsar(),loc=(1,1))board.add(Pulsar(),loc=(1,22))board.add(Pulsar(),loc=(1,42))# Simulate boardsim=sg.Simulator(board)sim.run(sg.rules.conway_classic,iters=1000)
Optionally, you can animate the simulation by runningsim.animate()
:
Aside fromPulsar
, we have anice collection oflifeformsfor you to choose from!
To install Seagull, run this command in your terminal:
pip install pyseagull
This is the preferred method to install Seagull, as it will always installthe 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 seagullpython setup.py install
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 yourBoard
, add yourLifeform
/s, and run theSimulator
given arule
. You can add multiple lifeforms as you want:
importseagullassgfromseagullimportlifeformsaslfboard=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 historysim.animate()
You can manually create your lifeforms by using theCustom
class:
importseagullassgfromseagull.lifeformsimportCustomboard=sg.Board(size=(30,30))board.add(Custom([[0,1,1,0], [0,0,1,1]]),loc=(0,0))
By default, the simulation statistics will always be returned after calling therun()
method. In addition, you can also obtain the history by calling theget_history()
method.
# The run() command returns the run statisticsstats=sim.run(sg.rules.conway_classic,iters=1000)# You can also get it using get_history()hist=sim.get_history()
You can find more examples in thedocumentation
This project is open for contributors! Contibutions can come in the form offeature requests, bug fixes, documentation, tutorials and the like! We highlyrecommend to file an Issue first before submitting aPullRequest.
Simply fork this repository and make a Pull Request! We'd definitelyappreciate:
- Implementation of new features
- Bug Reports
- Documentation
- Testing
MIT License (c) 2019, Lester James V. Miranda
About
A Python Library for Conway's Game of Life