🐍 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
Generates and prints proxies for the card game Magic: the Gathering

MTG-Proxy-Generator This program generates proxies for the card game Magic: the Gathering. These proxies can then be printed off and used. These copie

Carl L. 1 Jan 31, 2022
Given some input, spit out the possible words for a Wordle puzzle

Wordle Helper, because why not. Given some input, spit out the possible words for a Wordle puzzle First time setup # Download the dictionary to a file

Richard Duarte 1 Jan 25, 2022
A game made similar as space inveders with pygame

space-inveders-pygame a game made similar as space inveders with pygame . . . if you are using it make sure to change audio and imgs file i do no own

Volt_L18 2 Dec 26, 2021
Email guesser - Guessing BF email based on emailGuesser by WhiteHatInspector

email_guesser Guessing BF email based on emailGuesser by WhiteHatInspector (http

4 Dec 25, 2022
Replicating Minecraft World Generation inΒ Python

Minecraft World Generation in Python This is an attempt to replicate Minecraft world generation in Python. This is part of an article published on Med

Bilal Himite 159 Dec 19, 2022
PyCraft - A Minecraft launcher made in python

A Minecraft launcher made in python. The main objective of this launcher is to enable players to enjoy minecraft (especially those without a mojang/microsoft account). This launcher is not illegal as

38 Dec 12, 2022
Navicella cavallo, gioco 2D stile space shooter

Navicella Cavallo Il miglior gioco in circolazione Navicella cavallo Γ¨ un gioco 2D basato sullo stile dei giochi space shooter Come installare Navicel

Matteo 6 Jul 03, 2022
Mandaw 2 Mar 01, 2022
A chess engine with basic AI capabilities (search for best move using MinMax algorithm)

A chess engine with basic AI capabilities (search for best move using MinMax algorithm)

Ken Wu 1 Feb 02, 2022
MCRPC (Minecraft Resource Pack Comparator) checks your resource pack against any version of Minecraft to show resources missing from your pack for that version.

Minecraft Resource Pack Comparator MCRPC checks your resource pack against any version of Minecraft to show resources missing from your pack for that

3 Nov 03, 2022
The game company we work for has two events that we want to track: buy an item and join a guild. Each of them has metadata characteristic of such events.

The game company we work for has two events that we want to track: buy an item and join a guild. Each of them has metadata characteristic of such events.

Caro Arriaga 1 Feb 04, 2022
Wordle-player - An optimal player for Wordle. Based on a rough understanding of information theory

Wordle-player - An optimal player for Wordle. Based on a rough understanding of information theory

Neill Johnston 3 Feb 26, 2022
A top-down arcade space shooter made in pygame.

About: Journey Through Space is a top-down arcade shooter made in pygame. You play as a pilot who was left behind after a battle and the goal is to go

Crimson Sane 0 Jan 01, 2022
AutoPilot is a game where the player controls a car and tries to get the highest score he can while not dying under falling cement blocks.

AutoPilot AutoPilot is a game where the player controls a car and tries to get the highest score he can while not dying under falling cement blocks. C

Enoc Mena 1 Nov 17, 2021
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
Automates cubemap generation for Source Engine games.

AutoCube Automates cubemap generation for Source Engine games during compile-time. Download: see the release page Installation Using with CompilePal A

5 Feb 18, 2022
Pong is one of the first computer games that ever created, this simple

Pong-Game Pong is one of the first computer games that ever created, this simple "tennis like" game features two paddles and a ball, the goal is to de

Lateefah Ajadi 0 Jan 15, 2022
Un semplice Snake game , come negli anni 90!

Project-SnakeGame Un semplice Snake game , come negli anni 90! ITA VI porto un semplice giochino per i nostalgini degli anni 90 , ispirato al vecchio

Matt K Lawrence 1 Oct 17, 2021
This is a simple telegram bot for the game Pyal, a word guessing game inspired by Wordle

Pyal Telegram Bot This is a simple telegram bot for the game Pyal, a word guessing game inspired by Wordle. How does it work? Differently from the ori

Rafael Omiya 4 Oct 06, 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