Game of Life
April 28, 2020
Generation: 0
Earlier this month a great mathematician John Conway passed away due to COVID-19. Since few months (years) I wanted to implement his famous Game of Life. It is a cellular automation that is based on the initial state (therefore it's called a zero-player game). Here's a quick recap of the rules:
- It takes place on an infinite 2D grid
- Each square represents a cell
- Each cell can represent one of two states: alive or dead
Now, the lifecycle of the cells is defined by strict rules that define whether it will survive the next turn (generation). They are quite simple but provide the game with unexpected results and shapes. I will just copy-paste them here from Game of Life Wikipedia page:
- Any live cell with fewer than two live neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
Here's a basic (and highly inefficient) implementation of Conways's Game of Life. It is based on a grid of divs representing the cells. It is surprisingly small, as in this particular implementation each generation starts with a thorough check of every single cell (and there are 400 of them!). Click some squares to make the cells 'alive' and press the start button.