Skip to main content

Conway's game of life in python

Project description

Game Of Life

Simple way to play Conway's game of life in python.
You can import your own map as json file name "save.json", using get_MAP methode.
All you custom maps (in the save.json file) are available in the list custom_maps.
Other custom maps are available such as: my_map_1 and my_map_2, created using Map class :

from simple_game_of_life import Map
m = Map(100)
my_map_1 = m.mini_random_MAP((25, 20))
my_map_2 = m.kind(kind="line 10")

NOTE : Two artificials borders are created for each map,
The first one is visible while playing, it's in black.
The second one is white (invisible) just after the black border, no cell can born here

Installation

Run the following command to install:
$ pip install simple-game-of-life

Usage

for a random map

from simple_game_of_life import GameOfLife
game = GameOfLife(50) # 50 is the side (width, height) of the map
game.start_animation()

for a custom map

from simple_game_of_life import GameOfLife
from random import choice
my_custom_map = GameOfLife.get_MAP() 
game = GameOfLife(custom_map=choice(my_custom_map))
game.start_animation()
# Note you can also import custom_map like that :
# from simple_game_of_life import custom_map 

to implement a pattern :

from simple_game_of_life import GameOfLife, Map
glider = [[0,1,0],
          [0,0,1],
          [1,1,1]]
m = Map(100) # 100 is the side (width, height) of the map
my_map = m.my_pattern(glider)
game = GameOfLife(custom_map=my_map)
game.start_animation()

Other usage

GameOfLife classe :
- You can save a map by using saved_MAP methode.
- You can get a map by using get_MAP methode.
- You can reset all saved map by using reset_MAP methode.
- You can get all frames by using get_history methode.
- You can set a new animation with the same instance using new_animation methode.

Map classe :
- full_random_MAP : all the map gonna be random.
- mini_random_MAP : a portion of the map gonna be random.
- my_pattern : insert your pattern into an empty map.
- kind : insert well know pattern into an empty map, (currenly 5 patterns are available).
- random : choice randomly one of the following map
- glider
- lwss : Lightweight spaceship
- mwss : Middleweight spaceship
- hwss : Heavyweight spaceship

You can also calculate the average time of instancing, using timeit function:

game = timeit(GameOfLife, loop=10, size_or_side=50, frames=200) # loop : number of loop
game.start_animation()

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

simple_game_of_life-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_game_of_life-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file simple_game_of_life-0.1.0.tar.gz.

File metadata

  • Download URL: simple_game_of_life-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for simple_game_of_life-0.1.0.tar.gz
Algorithm Hash digest
SHA256 06144e74963abcda930362545584a59ec137c692d2c9e00e2dc8c953860af1b8
MD5 52561576c9731a8c33b8ba5613079052
BLAKE2b-256 c756632e89990e94ec964db78f86e1ced20dfa52bc4dc0850b560a8315ad6590

See more details on using hashes here.

File details

Details for the file simple_game_of_life-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_game_of_life-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b876c28ea182e9dee4454dc18d14b13d97821e882f5de98be6d2ea7cceb6bc15
MD5 b10fc4e60c4d3218818cf78132570da8
BLAKE2b-256 e301ca0e2401c8cf7b6652e25f3986eaff57a1894ef9add2250a5a28cec75333

See more details on using hashes here.

Supported by

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