Game of Life (C++)



The Game of Life is an example of a cellular automaton, invented in 1970 by the British mathematician John Horton Conway. The game exists of a regular grid with cells. The cells can either be “dead” or “alive”. These states are determined by the following rules:

  1. Any live cell with fewer than two live neighbours dies, as if caused 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.

Started: Oktober 2017
Finished: March 2018


Source Code


Most of the magic happens in the “Grid” class. This class creates a multidimensional array filled with cells (code from this class can be found in the link above). These cells are randomly defined dead or alive. The function “generateNext()” gets called from the main.cpp every generation. This function displays the cells and saves the state of each one of them, so it can loop through them all to check each of their neighbours. With this number, the “updateCell()” function determines if a cell should be dead or alive in the next generation.