Conway's Game of Life in Python 3.6
Conway’s Game of Life in Python 3.6.
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...')
# Simulate a random 'The Game of Life' in a Posix-compatible terminal
python3 main.py
Technology | |
---|---|
Language | Python 3.6 |
Linter | Flake8 3.5 |
# 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
Use test discovery to run all unit tests at once.
# Run tests
python -m unittest discover
The project uses PEP8. Flake8 is setup to enforce the rules.
# Run flake8
flake8