🐍 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
python script to convert .OBJ files into Minecraft, rendering them in game with a core shader.

samples: random notes about the tool general output format: (animation not supported yet but planned) vertex id Minecraft's gl_VertexID isn't per mode

199 Jan 02, 2023
PyUnity is a Python implementation of the Unity Engine, written in C++

PyUnity is a Python implementation of the Unity Engine, written in C++. This is just a fun project and many features have been taken out to make it as easy as possible to create a scene and run it.

PyUnity 206 Jan 03, 2023
An open source Python library for the Snake retro game.

An open source Python library for the Snake retro game.

3 Jul 13, 2021
The original Tetris tile-matching game as adopted by IBM PC.

🕹️ Tetris Game The original Tetris tile-matching game as adopted by IBM PC. Game developed purely on python using the Dear PyGui Framework. 📖 Instru

14 Nov 12, 2022
A small Python Library to process Game Boy Camera images

GameBEye GameBEye is a Python Library to process Game Boy Camera images. Source code 📁 : https://github.com/mtouzot/GameBEye Issues 🆘 : https://gith

Martin TOUZOT 4 Nov 25, 2022
Track your favorite minecraft servers' (too bee too tee) queue at any time at your own convenience!

2b2t Queue Monitor Track your favorite minecraft servers' (too bee too tee) queue at any time at your own convenience! Compiled Usage go to https://gi

Addi 1 Feb 05, 2022
This is game 2048 created with moudle of python tkinter and OOP.

Game 2048 This is game 2048 created with moudle of python tkinter and OOP. This game build on classes. For start this game run: If you have python ver

0 Nov 02, 2021
An environment to run atari-like games in VGDL.

vgdl An environment to run atari-like games in VGDL. Requirements python = 3.6 Installation pip install -r requirements.txt Usage # Create an enviro

Sergio Arnaud Gomez 1 Dec 24, 2021
A menu for pygame. Simple, and easy to use

pygame-menu Source repo on GitHub, and run it on Repl.it Introduction Pygame-menu is a python-pygame library for creating menus and GUIs. It supports

Pablo Pizarro R. 411 Dec 27, 2022
WordleHelper suggests words to help players better enjoy the hit game Wordle

WordleHelper Introduction WordleHelper suggests words to help players better enjoy the hit game Wordle. Both the general mode and the hard mode are su

Shao-Yu, Chu 5 Jun 02, 2022
Wordle - Wordle Clone With Python

Wordle Clone Python This is a cli clone of the famous wordle game developed by J

Shivam Pandya 20 Jul 07, 2022
A simple hangman game for beginners trying to learn python

Hangman Game This is a simple hangman game for beginners trying to learn python. I have tried to keep it as simply as possible. Sample output Here is

1 Oct 13, 2021
Netskrafl - an Icelandic crossword game website

Netskrafl - an Icelandic crossword game website English summary This repository contains the implementation of an Icelandic crossword game in the genr

Miðeind ehf 30 May 09, 2022
Dota2 AI bot - Last Order Dota2 Solo AI

Last Order Dota2 Solo AI 该库提供一个由强化学习训练出的Dota2影魔solo智能体。该智能体通过自我对战的训练方式训练,从随机动作开始学习复杂的策略。玩家可以与该智能体进行影魔solo对战。 对战规则 1.物品方面不可以出凝魂之露,灵魂之戒,魔瓶,真眼。 2.不可以吃符,或

bilibili 365 Jan 05, 2023
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 better MCPi Launcher

Planet Launcher A better, maintained launcher for the Minecraft: Pi Edition Reborn mod. Report Bug | Request Feature Planet is a maintained, feature-r

15 Oct 19, 2022
This is simple minesweeper-like Telegram game

This is simple minesweeper-like Telegram game. You need to open all "free" squares and put flags on squares with bombs on them. If you open a cell with a bomb, the game is over.

Aleksandr 32 Dec 31, 2022
A multiplayer RPG Discord bot, where you play as a god.

To run Ensure your Python is up to date, and install packages from requirements.txt Duplicate secrets-template.yaml, and name it secrets.yaml Insert y

4 Jan 18, 2022
In the works, creating a new Chess Board and way to Play...

sWJz4KingsChess date started on github.com 11-13-2021 In the works, creating a new Chess Board and way to Play... starting to write this in Pygame, an

Shawn 2 Nov 18, 2021
Python fitting assistant, cross-platform fitting tool for EVE Online

pyfa What is it? Pyfa, short for python fitting assistant, allows you to create, experiment with, and save ship fittings without being in game. Open s

1.4k Dec 22, 2022