🐍 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
2DMC is an abrrieviation for 2 Dimensional Minecraft.

2DMC 2DMC is an abrrieviation for 2 Dimensional Minecraft. This idea is originally created and implemented by Griffpatch on Scratch. This is a persona

DaNub 5 Nov 06, 2022
Deal Or No Deal was a very popular game show. Even now, for a family party, it's a fun game to pass time

Deal Or No Deal was a very popular game show. Even now, for a family party, it's a fun game to pass time. I made a code to play the game right in your terminal/console. This isn't made to be a game w

1 Feb 15, 2022
Python Program: Hilo Game

Python Program: Hilo Game 🂡 Description Hilo is a game in which the player gues

2 Jan 22, 2022
Dueling Platform for Competitive Programming. Learn through Games.

CP-Dueling Dueling Platform for Competitive Programming. Learn through Games. Setting Up Minimum Python version needed = 3.9.9 Install Virtualenv and

Bhavesh 3 Feb 07, 2022
Cricket game using PYQT

Cricket-game-using-PYQT This is a Fantasy cricket Desktop application build in p

Sanket Mane 1 Jan 03, 2022
A Tetris game made using PyGame as renderer only, for a school project.

Tetris_Python A Tetris game made using PyGame as renderer only, for a school project. Twist in the Game Blocks can pentrate through right and left bou

Ravi Arora 2 Jan 31, 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
Console 2D GameEngine {C2DGE} [0.1.0]

Console 2D GameEngine {C2DGE} [0.1.0] By Grosse pastèque#6705 The Project's Goal : This projects was just a challenge so if you have bad reviews, it's

Big watermelon 1 Nov 06, 2021
Battle of Saiyans: Goku v Vegeta is a 1 v 1, (Player vs CPU) 2D Martial arts fighting game

Battle of Saiyans: Goku v Vegeta is a 1 v 1, (Player vs CPU) 2D Martial arts fighting game inspired by the popular anime series Dragon Ball Z The game

ARZ 3 Feb 16, 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
A simple pygame implementation of the LOGO programming language.

LOGO-py A simple pygame implementation of the LOGO programming language. Latest Version Notes Fixed a bug where penup/pendown would not work properly.

Ethan Evans 1 Dec 05, 2021
A Pygame game made in 48 hours

Flappuccino Flappuccino is a game created in 48 hours for the PyGame Community New Years Jam using Python with Pygame. Screenshots Background Informat

PolyMars 242 Jan 02, 2023
linorobot2 is a ROS2 port of the linorobot package

linorobot2 is a ROS2 port of the linorobot package. If you're planning to build your own custom ROS2 robot (2WD, 4WD, Mecanum Drive) using accessible parts, then this package is for you. This reposit

linorobot 195 Dec 29, 2022
A very bad wordle solver to help me solve the daily wordle

Wordle Solver A very bad wordle solver to help me solve the daily wordle on https://www.powerlanguage.co.uk/wordle/ TODO list take into account letter

Logan Anderson 4 Feb 03, 2022
Wordle-Python - A simple low-key clone of the popular game WORDLE made with python and a 2D Graphics module Pygame

Wordle-Python A simple low-key clone of the popular game WORDLE made with python

Showmick Kar 7 Feb 10, 2022
Disables the chat in League of Legends for Windows.

Disables the chat in League of Legends for Windows. If you simply can't stop yourself from typing LeagueStop will play KEKW.mp3 each time you try. The sound will stack & becomes horribly annoying.

1 Nov 24, 2021
Jogo Flappy Bird com phyton e phygame

Flappy-Bird Tecnologias usadas Requisitos para inicializar o jogo: Python faça o download em: https://www.python.org/ Pygame faça o download em: https

João Guilherme 1 Dec 06, 2021
Tic tac toe game developed by naman in python

TIC TAC TOE GAME DEVELOPED BY NAMAN IN PYTHON . IT USES MINMAX ALGORITHM TO COMPETE IN DIFFICULTY MODE

Naman Anand 4 Jun 24, 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
A python snake game based on pygame.

PySnake A python snake game based on pygame. Requirements Package version pygame = 2.1.2 opencv-python = 4.5.1.48 Run Windows python main.py Linux &

2 Jan 31, 2022