🐍 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
Owner
Mateusz Żebrak
👨‍🎓 A third-year Computer Science student                    🔥 Hugely interested in blockchain technology
Mateusz Żebrak
Multiplayer 2D shooter made with Pygame

PyTanks This project started as a one day project with two goals: Create a simulated environment with as much logic as possible written in Numpy, to o

Felix Chippendale 1 Nov 07, 2021
This is a Python solver for the game Wordle, which recently received its PT-BR version

PT_BR_Wordle_Solver Este é um solver feito em Python do jogo Wordle, que recebeu sua versão PT-BR recentemente. Onde jogar Os sites para se jogar mais

Vinicius Jameli 1 Jan 24, 2022
Crazy fast kahoot game flooder with a GUI and multi OS support.

kahoot flooder Crazy fast kahoot game flooder with a GUI and multi OS support. Made in python using tkinter and KahootPY with toast notifications. Req

Ben Tettmar 1 Apr 09, 2022
This is a simple game of rock-paper-scissors developed in Python

This is a simple game of rock-paper-scissors developed in Python. It allows two players to play with one another on different command lines through networking.

NAMAN JAIN 3 Oct 21, 2022
Flappy-Bird AI - Flappy Bird game with AI

FLAPPY BIRD AI Flappy Bird game solved with neat-python, a Python module based o

1 Jan 07, 2022
The Original Snake Game. Maneuver a snake in its burrow and earn points while avoiding the snake itself and the walls of the snake burrow.

Maneuver a snake in its burrow and earn points while avoiding the snake itself and the walls of the snake burrow. The snake grows when it eats an apple by default which can be disabled in the setting

17 Nov 12, 2022
Simple wordle clone + solver + backtesting

Wordle clone + solver + backtesting I created something. Or rather, I found about this game last week and decided that one challenge a day wasn't goin

1 Feb 08, 2022
Guess Your Card - A Multiplayer Python Game

Guess Your Card - A Multiplayer Python Game This is a guessing card game having two levels - Developed in Python and can be played between two to four

Hammad Ahmed ~ 1 Oct 20, 2021
Simple Game created using Python & PyGame, as my Beginner Python Project!

Space Invaders This is a simple SPACE INVADER game create using PYGAME whihc have sound and lot's of keyboard functions. Prerequisites More Experience

Gaurav Pandey 2 Jan 08, 2022
Chess GUI

Lucas Chess Lucas Chess is a GUI of chess: To learn to play chess. To play chess against engines. Dependencies Python 2.7 PyQt4 PyAudio psutil Python

Lucas 322 Dec 20, 2022
Chess - A python gui application

Chess Python version 3.10 or greater is required to play. Note This is a gui application, and as such will not run inside WSL.

Jonxslays 1 Dec 16, 2021
使用python编写2048游戏及自动玩

使用python编写2048游戏及自动玩

tiger-wang 68 Dec 23, 2022
An old time game Tic-Tac-toe

A Tic Tac Toe Bot This is the code repository for my article on Medium - Playing Games with Python - Tic Tac Toe, where I have tried to take the famou

Jigyanshu 0 Feb 25, 2022
Wordlebot - A simple Wordle puzzle solver in python

WordleBot A simple search-based puzzle solver for Wordle, built in Python. Inspi

Rob Kimball 2 Jan 27, 2022
Discord.py Gaming Bot🎮, for fun & engaging discord minigames

Status 🧭 This Project will not no longer be developed/finished due to a) discord.py's ( main dependency ) discontinuation b) My personal lack of int

Wordsetter 11 Nov 21, 2022
Flappy Bird clone utilizing facial recognition to move the

Flappy Face Flappy Bird clone utilizing facial recognition to move the "bird" How it works Flappy Face uses Facial Recognition to detect your face's p

Brady McDermott 1 Jan 11, 2022
This a Chess PGN saver which allows you to save your game pgns, in a .pgn file

PGN Saver This a Chess PGN saver which allows you to save your game pgns, in a .pgn file This can be a very useful tool for the people using chessbase

3 Jan 06, 2022
Flappy Bird clone in Python using Pyglet

python_Flappy-Bird This is the Game Flappy Bird which was originally developt by Dong Nguyen under .Gears recreated in Python. Requirements (used to d

Konstantin Opora 1 Dec 10, 2021
Repository with console python implementation of Simple Artificial Life (simplified MAS) and Conway's game of life

artificial-life-game Repository with console python implementation of Simple Artificial Life (simplified MAS) and Conway's game of life Installation c

Vladislav 6 Nov 14, 2022
a simple keyboard game

Maxwell-Demon-Game Powered by Taichi. a simple keyboard game This is hw2 of Taichi course, as a basic exercise of class. Rigid 2d bodies and resolve c

8 Feb 01, 2022