... is a cellular automaton devised by Mathematician John Conway. It is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input.
The universe of the Game of Life is an infinite, two-dimensional orthogonal grid of square cells, (in this project a 60 x 80 grid of square cells) each of which is in one of two possible states, live (1)
or dead (0)
(or populated and unpopulated, respectively). Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time (or simply generation) , the following transitions occur:
- Any live cell with two or three live neighbours survives.
- Any dead cell with three live neighbours becomes a live cell.
- All other live cells die in the next generation. Similarly, all other dead cells stay dead.
For the game's implementation we have made use of the pygame
and numpy
modules.
The update()
method takes an array of cells (60 x 80 in size), and returns an array of cells of the corresponding next generation, after applying the above mentioned rules.
As the program begins, it is paused, i.e. by click-dragging your mouse over the square cells, you can make them alive.
As soon as SPACEBAR
is pressed, it resumes and the generations begin to change.
game_of_life_demo.mp4
Example gameplay
Big thanks to Neural Nine! Was really helpful in Understanding the game mechanics and efficient implementation