41.1 Problem

Let’s finish with another classic. This time your job is to implement Conway’s Game of Life with a finite two dimensional grid called the universe. Each cell on the grid got some initial probability of being alive. Per the Wikipedia’s description the next state of the universe is calculated as follows:

  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.

The game may look something like Figure 25.

Figure 25: A frame from the Conway’s Game of Life.

WARNING: While running the program in terminal the screen may flicker. If that’s a problem (you may feel unwell) then you can skip this exercise. Remember that you should be able to abort the program (terminal application) at any time by pressing Ctrl-C.



CC BY-NC-SA 4.0 Bartlomiej Lukaszuk