Skip to main content

TDD-style implementation of Conway's Game of Life in Python

Project description

Build Status

py-conway

TDD-style implementation of Conway's Game of Life in Python. Built with zero dependencies in order to be portable to Web, CLI and embedded applications.

View Project on PyPi

Installation

pip install py-conway

Usage

To create a game, you'll need to provide dimensions and a starting two-dimensonal list to function as the game board. For example:

from conway.game import Game

beacon = [[0, 1, 0],
          [1, 1, 1],
          [0, 1, 0]]

new_game = Game(3, 3, beacon)

Once the game board is populated, call the start() method. The game will start on a background thread and update the full game board as well as a number of informational instance variables:

new_game.start()

new_game.board # hold the complete game state after each step
new_game.live_cells # the count of live cells on the board
new_game.num_steps # the number of steps elapsed in the current game.

It's also possible to call the step() method and control the game state yourself from one iteration to the next:

new_game.step()

Here's an example that runs the game and plots the game board after intialization and the first step:

import matplotlib.pyplot as plt
from py-conway import Game

def create_zeros(x, y):
    dim_one = [0 for item in range(x)]
    return [dim_one[:] for item in range(y)]

beacon = create_zeros(12, 12)

beacon[0][1] = 1
beacon[1][2] = 1
beacon[2][3] = 1
game = Game(12, 12, beacon)

plt.imshow(game.beacon, cmap='binary')
plt.show()

game.step()

plt.imshow(game.beacon, cmap='binary')
plt.show()

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

py-conway-0.0.2.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

py_conway-0.0.2-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

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