Game of Life
The Game of Life (Conway's Game of Life) is a very classic zero-player game. It was invented by British mathematician John Horton Conway in 1970.
It is called a "zero-player" game because it evolves by itself using simple rules, and can create very complex patterns automatically.
The game happens on a 2D grid. Each cell on the grid can be alive or dead.
The state of each cell is decided by its eight neighbors (up, down, left, right, and four diagonals). The rules are:
- Loneliness Death: If a live cell has fewer than 2 neighbors, it dies from loneliness.
- Survival: If a live cell has 2 or 3 neighbors, it stays alive in the next generation.
- Overcrowding Death: If a live cell has more than 3 neighbors, it dies from overcrowding.
- Reproduction: If a dead cell has exactly 3 neighbors, it becomes a live cell.
With these simple rules, if you give an initial state, the game can keep evolving by itself. The cells on the board will keep living and dying. In the end, the board may reach a stable state (the number of live cells does not change), or it may keep creating new cells forever.
On the website's game panel, your task is to finish the most important part of the Game of Life: write an algorithm to calculate the result of each evolution step using the rules above.
After you submit the correct code, the game should evolve by itself. The game has several classic starting states. You can choose different presets from the dropdown, click the start button, and watch how they evolve.