Skip to content

ab5olute/GameOfLife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GameOfLife

A Python implementation of Conway's Game of Life with PyGame module.

Rules

  1. Any live cell with two or three live neighbours survives.
  2. Any dead cell with three live neighbours becomes a live cell.
  3. All other live cells die in the next generation. Similarly, all other dead cells stay dead.

Example of GameOfLife usage

>>> life = GameOfLife.from_file('figures/glider.txt')
>>> life.curr_generation
[[0, 1, 0, 0, 0],
 [0, 0, 1, 0, 0],
 [1, 1, 1, 0, 0],
 [0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0]]
>>> for _ in range(4):
...    life.step()
>>> life.curr_generation
[[0, 0, 0, 0, 0],
 [0, 0, 1, 0, 0],
 [0, 0, 0, 1, 0],
 [0, 1, 1, 1, 0],
 [0, 0, 0, 0, 0]]
>>> life.save('glider-4-steps.txt')

Pygame Controle Settings

  • To pause the game: press SPACE key.
  • To draw or remove cell: click LEFT MOUSE button.

Run tests

python -m unittest discover

Demo

Demo

About

Conway's Game of Life in Python with PyGame

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages