Skip to content

alexeykostevich/game-of-life-in-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

100 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conway's Game of Life in Python

Conway's Game of Life in Python 3.6.

Demo

Simulate for a random world:

from life import Cell, originate_from, WrappedUniverse


# Create a random wrapped universe of 10 x 10
universe = WrappedUniverse.random(10, 10, Cell.likely)
# Get a universe generator iterator
life = originate_from(universe, regenerate=Cell)

# Iterate through life and print the universe on each step
for universe in life:
    print(universe)
    input('Press Enter to continue...')

Simulate for a world from ASCII art:

from life import originate_from, WrappedUniverse


with open('universe.txt') as file:
    # Create a universe from the file
    universe = WrappedUniverse.from_data(file.readlines(), is_cell=lambda s: not s.isspace())

# Get a universe generator iterator
life = originate_from(universe, regenerate=lambda: '*')

# Iterate through life and print the universe on each step
for universe in life:
    print(universe)
    input('Press Enter to continue...')

Demo

# Simulate a random 'The Game of Life' in a Posix-compatible terminal
python3 main.py

Technology Stack

Technology
Language Python 3.6
Linter Flake8 3.5

Development

Prerequisites

  1. Python 3.6

Quickstart

# Create a Python virtual environment
python3 -m venv .venv

# Activate a Python virtual environment
.venv/bin/activate

# Install the dependencies
$ pip install -r requirements.txt

Unit Tests

Use test discovery to run all unit tests at once.

# Run tests
python -m unittest discover

Styleguide

The project uses PEP8. Flake8 is setup to enforce the rules.

# Run flake8
flake8

About

Conway's Game of Life in Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages