Maxiviper117 / python-conways-game-of-life

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conway's Game of Life is a cellular automaton devised by the mathematician John Horton Conway. It's a zero-player game that simulates the life cycle of cells on a two-dimensional grid based on a set of simple rules. The grid consists of cells that can be in one of two states: alive or dead. The state of the cells evolves in discrete steps according to the following rules:

Rule Description
Underpopulation Any live cell with fewer than two live neighbors dies, as if by underpopulation.
Survival Any live cell with two or three live neighbors lives on to the next generation.
Overpopulation Any live cell with more than three live neighbors dies, as if by overpopulation.
Reproduction Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Detailed Explanation

  • Neighbors: Each cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent.
  • Grid Evolution: The state of the grid evolves simultaneously; all cells are updated at the same time based on the rules.
  • Initial Configuration: The initial state of the grid is provided as the starting point, and subsequent states are generated by applying the rules iteratively.

Example

Consider a 3x3 grid with the following initial state:

0 1 0
0 1 0
0 1 0

Here, 1 represents a live cell and 0 represents a dead cell.

Applying the rules:

  1. The live cell at (1, 1) has two live neighbors (itself and the cell directly below it), so it remains alive.
  2. The live cell at (2, 1) has only one live neighbor (the cell directly above it), so it dies due to underpopulation.
  3. The live cell at (3, 1) has two live neighbors (itself and the cell directly above it), so it remains alive.
  4. The dead cells at (2, 0) and (2, 2) each have three live neighbors, so they become alive due to reproduction.

Next generation state:

0 0 0
1 1 1
0 0 0

In this way, the game continues to evolve according to the rules of underpopulation, survival, overpopulation, and reproduction.

About


Languages

Language:Python 100.0%