Conways’s Game Of Life is a Cellular Automation Method created by John Conway. This game was created with Biology in mind but has been applied in various fields such as Graphics, terrain generation,etc..
The “game” 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, or, for advanced “players”, by creating patterns with particular properties.
How the game works
Because the Game of Life is built on a grid of nine squares, every cell has eight neighboring cells,as shown in the given figure. A given cell (i, j) in the simulation is accessed on a grid [i][j], where i and j are the row and column indices, respectively. The value of a given cell at a given instant of time depends on the state of its neighbors at the previous time step. Conway’s Game of Life has four rules.
- If a cell is ON and has fewer than two neighbors that are ON, it turns OFF
- If a cell is ON and has either two or three neighbors that are ON, it remains ON.
- If a cell is ON and has more than three neighbors that are ON, it turns OFF.
- If a cell is OFF and has exactly three neighbors that are ON, it turns ON.
So since we know how it works, the next thing we need to figure it out that how to make it work.
1. Initialize the cells in the grid. 2. At each time step in the simulation, for each cell (i, j) in the grid, do the following: a. Update the value of cell (i, j) based on its neighbors, taking into account the boundary conditions. b. Update the display of grid values.
After we done here lets get our hands on code.
:For 2D array(matrix) manipulation.
:For update the simulation or in easy words to make stuffs move.
:To pass command line arguments in the code.
Now lets get it started
Without passing any command line arguments.
Now lets turn up things a little, let’s see what happens if add updates the animation every 500 milliseconds and setting up the dimensions 32X32 and also using the initial glider pattern.
python 'filename.py' --grid-size 32 --interval 500 --glider
You can try manipulating this code to create different simulation using this.
- Github Code for this article
- Book: Python Playground: Geeky Projects for the Curious Programmer
- docs matplotlib
This article is contributed by Subhajit Saha. If you like GeeksforGeeks and would like to contribute, you can also mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program for Conway's Game Of Life
- Program for Conway’s Game Of Life | Set 2
- Python implementation of automatic Tic Tac Toe game using random number
- Hangman Game in Python
- Color game using Tkinter in Python
- Hangman Game in Python
- Python | Program to implement Jumbled word game
- Python | Catching the ball game
- Python | Program to implement simple FLAMES game
- Python | Simple FLAMES game using Tkinter
- 21 Number game in Python
- Python program for word guessing game
- Python | Pokémon Training Game
- Mastermind Game using Python
- Number guessing game in Python 3
- Introduction to pyglet library for game development in Python
- Number Guessing Game in Python using Binary Search
- Tic Tac Toe Game using PyQt5 in Python
- 2048 Game in Python
- Create a Simple Two Player Game using Turtle in Python