Game of Life

April 28, 2020

Generative
Algorithms


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:

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:

  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.

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.