项目作者: alexeykostevich

项目描述 :
Conway's Game of Life in Python 3.6
高级语言: Python
项目地址: git://github.com/alexeykostevich/python-game-of-life.git
创建时间: 2017-12-03T17:33:01Z
项目社区:https://github.com/alexeykostevich/python-game-of-life

开源协议:MIT License

下载


Conway’s Game of Life in Python

Conway’s Game of Life in Python 3.6.

Demo

Simulate for a random world:

  1. from life import Cell, originate_from, WrappedUniverse
  2. # Create a random wrapped universe of 10 x 10
  3. universe = WrappedUniverse.random(10, 10, Cell.likely)
  4. # Get a universe generator iterator
  5. life = originate_from(universe, regenerate=Cell)
  6. # Iterate through life and print the universe on each step
  7. for universe in life:
  8. print(universe)
  9. input('Press Enter to continue...')

Simulate for a world from ASCII art:

  1. from life import originate_from, WrappedUniverse
  2. with open('universe.txt') as file:
  3. # Create a universe from the file
  4. universe = WrappedUniverse.from_data(file.readlines(), is_cell=lambda s: not s.isspace())
  5. # Get a universe generator iterator
  6. life = originate_from(universe, regenerate=lambda: '*')
  7. # Iterate through life and print the universe on each step
  8. for universe in life:
  9. print(universe)
  10. input('Press Enter to continue...')

Demo

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

Technology Stack

Technology
Language Python 3.6
Linter Flake8 3.5

Development

Prerequisites

  1. Python 3.6

Quickstart

  1. # Create a Python virtual environment
  2. python3 -m venv .venv
  3. # Activate a Python virtual environment
  4. .venv/bin/activate
  5. # Install the dependencies
  6. $ pip install -r requirements.txt

Unit Tests

Use test discovery to run all unit tests at once.

  1. # Run tests
  2. python -m unittest discover

Styleguide

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

  1. # Run flake8
  2. flake8