🐍 Conway's Game of Life cellular automaton implemented in PyGame

Overview

Conway's Game of Life

My PyGame implementation of Conway's Game of Life.
This implementation involves treating all edges of the grid as stitched together yielding a toroidal array.
Be sure to check all of the features and controls below πŸ˜ƒ

Sections

  1. What is the game of life
  2. Rules
  3. Presentation
  4. Configuration
  5. Running
  6. Features / Controls

What is the game of life

link to the source [wikipedia.org]

The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.

It is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. It is Turing complete and can simulate a universal constructor or any other Turing machine.

Rules

link to the source [wikipedia.org]

The universe of the Game of Life is an infinite, two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead, (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, the following transitions occur:

  1. Any live cell with fewer than two live neighbours dies, as if by underpopulation.
  2. Any live cell with two or three live neighbours lives on to the next generation.
  3. Any live cell with more than three live neighbours dies, as if by overpopulation.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

These rules, which compare the behavior of the automaton to real life, can be condensed into the following:

  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.

Presentation

Configuration

It is possible to run a .bat file with appropriate parameters modifying the program settings. If you want to check this out, just edit the .bat file.

All parameters are optional, but when used, they take priority over the configuration settings in the Settings class.

Example configuration: @py __main__.py -s 16 --gens_per_sec 10 -W 1280 -H 720 -F "../patterns/spacefiller.txt"
Here are the parameters that can be set:

Shortcut Parameter Description Values
-h --help show the help message and exit
-s --size startup size of each cell (INT x INT) between MIN_CELL_SIZE and MAX_CELL_SIZE
-f --fps set the framerate cap during the game must be greater or equal 1
-g --gens startup number of generations per sec between MIN_GENS_PER_SEC and MAX_GENS_PER_SEC
-W --width startup screen width must be greater than MIN_WIDTH
-H --height startup screen height must be greater than MIN_HEIGHT
-F --file relative path from main to the folder with the file ex. -F "../patterns/glider.txt"

Running

  1. If you are using Python launcher

    • Install PyGame via CMD using:

        py -m pip install pygame
      
    • Then simply run the game by launching:

        gameoflife.bat
      
  2. If you are using Python executable

    • Install PyGame via CMD using:

        pip install pygame
        
        or
      
        python -m pip install pygame
      
    • Then you need to edit the .bat file. This is what you need to enter:

        @python instead of @py
      
    • Then simply run the game by launching:

        gameoflife.bat
      
  3. If you want to run this app with your IDE, just run the __main__.py

Features / Controls

  • In addition to changing the generation per second with the keys, you can use the mouse scroll. While holding down the CTRL key, you can also resize the cell with the scroll.
  • When reading from a file, a living cell is marked as '1', 'o' or 'O'. In turn, a dead cell can be written as '0', '.' or ''.
    Additionally, there is no need to fully complete the rows with dead cells, because they are completed automatically to align with the longest row.
    If you want the whole line to be filled with dead cells, just hit enter, but make sure the last line contains a character like ' ', '0', '.' or '
    '
  • There is a possibility to change the size of the window with the mouse by stretching the application window and cell alignment will be the same as before.
  • When decreasing the size of a single cell, the number of cells in the grid increases, but the old cell alignment is retained.
  • By increasing the size of a single cell, their number in the grid decreases, however, the new grid includes all cells relative to the top left corner.
  • It is possible to revive / kill cells with the mouse while the game is not paused, but sometimes it may be necessary to reduce the number of generations per second so that the update does not run too fast.
  • Cells that remain in the same place change their color with the number of generations - through purple until they are completely blue.
  • The current settings with the fps counter are displayed in the auxiliary menu available under the F1 button.



Command Description Values / Info [ ] - startup
F1 show / hide help menu
g show / hide additional grid [GREY], WHITE, HIDDEN
w show / hide cells route
e set the next color for dead cells WHITE, [LIGHTEST_GREY], LIGHTER_GREY, LIGHT_GREY
p run / pause the game
s save current grid to a file
r randomize grid
n display next generation (use when game is paused)
t switch between cell sizes 8x8, [16x16], 32x32, 64x64
z | x
OR VIA
<CTRL> + <MOUSE WHEEL>
adjust cell sizes
by -+ val of CHANGE_CELL_SIZE
range between MIN_CELL_SIZE and MAX_CELL_SIZE
, | .
OR VIA
<MOUSE WHEEL>
generations per second
-+ val of CHANGE_GENS_PER_SEC
range between MIN_GENS_PER_SEC and MAX_GENS_PER_SEC
<LMB> revives the indicated cell (can be held for quicker setting)
<RMB> kills the indicated cell (can be held for quicker setting)
q quit the game
You might also like...
Simple python program to simulate Conway's game of life with custom variables.

ConwaysGameOfLife Simple python program to simulate Conway's game of life with custom variables. Custom Variables Grid-size : Change the size of the p

A small fun project to simulate Conway's Game of Life, created in Python.

A small fun project to simulate Conway's Game of Life, created in Python. Conway's Game of Life simulates a grid of cells, where the state of each cell consists of whether the cell is alive or dead.

made a life sim game because i was tired of a astray gamedev company, everything here is open-source

Srel made a life sim game because i was tired of a astray gamedev company, everything here is open-source Progress Currently making the cmd-line versi

A Game of Life implementation in Python
A Game of Life implementation in Python

Game of Life in Python (Golipy) Golipy is a simulator of John H. Conway's Game of Life, developed in Python based on the Pygame library. This is a toy

Graphical impimetaion of Conway's Game of Life in Python using pyglet

Conway's Game of Life in Python Konstantin Opora Conway's Game of Life: graphical implementation in python using pyglet. developed in Python 3.10.0 Re

Synthesizer based on Conway's Game of Life

Conway Synth Synthesizer based on Conway's Game of Life Trying to avoid step sequencer fashions that have been done before and basing it on actual cel

Stock game is a python program that simulates real-life stock marketing, saving, and investments

Stock game is a python program that simulates real-life stock marketing, saving, and investments. Users get to trade and manage their portfolio and manage their 100,000 dollar portfolio.

An implementation of John Conway's Game of Life.

This is an implementation of John Conway's Game of Life in Python, and a very basic and straightforward one at that.

Blender Game Engine Game Type Templates Logic Bricks (and Python script) based Game Templates for Blender

Blender-Game-Engine-Templates Blender Game Engine Game Type Templates Logic Bric

Owner
Mateusz Ε»ebrak
πŸ‘¨β€πŸŽ“ A third-year Computer Science student                    πŸ”₯ Hugely interested in blockchain technology
Mateusz Ε»ebrak
An interactive pygame implementation of Conway's Game of Life

Game of Life An interactive pygame implementation of Conway's Game of Life Installation Clone the repo and navigate into it. git clone https://github.

Ethan 1 Dec 5, 2021
A pygame implementation of John Conway's Game of Life

Game of Life A Pygame Simulation This is a Pygame implementation of the famous Conway's Game of Life. The game features a set of very simple rules: An

null 1 Jan 6, 2022
Scalable computer implemented in the game of life.

scalable-gol-computer This is a computer built in Conway’s game of life. It supports variable sizes of 8, 16 and 32 bit. Maximum program size: 256 lin

Nicolas Loizeau 19 Nov 19, 2022
PyCheckers - A classic board game implemented in pygame

PyCheckers! A classic board game implemented in pygame! Complete with every feature you need to play checkers! (including handsome sprites drawn by a

helaxious 1 Jan 21, 2022
Snake game mixed with Conway's Game of Life

SnakeOfLife Snake game mixed with Conway's Game of Life The rules are the same than a normal snake game but you have to avoid cells created by Conway'

Aidan 5 May 26, 2022
PyGame-Tutorial - Refrence for building games in pygame

PyGame-Tutorial How to build games using the python library PyGame End result Ho

St. Mark's Computer Science Club 2 Jan 9, 2022
a game of life implementation in python

gameoflife-py python implementation of game of life Installing As long as you have bash and curl installed and are on Linux the install script should

Raghav 5 Jun 9, 2021
Implementation of Conway's game of life in python.

?? ????‍?? Conway's Game of Life ????‍?? ?? by FranciscoCharles An interactive simulator that implements the standard Conway Game of Life with a simpl

null 3 Oct 1, 2021
A tool to design a planet for Galaxy Life Reborn game.

GLRBaseDesigner A program to design your planet for Galaxy Life Reborn game. Description Do you want to share your base design with friends? Now it's

jjay31 9 Dec 16, 2022
Game of life, with python code.

Game of Life The Game of Life, also known simply as Life, is a cellular automaton. It is a zero-player game, meaning that its evolution is determined

Mohammad Dori 3 Jul 15, 2022