Conway’s Game of Life Andrew Williams
Conway’s Game of Life ► Conceptualized in late 1960s ► Popularised in a Scientific American article about John Horton Conway (URL constructed on 10/10/2007) ► Conway is a mathematician from Liverpool Currently (2007) Professor of Mathematics at Princeton University
Conway’s Game of Life ► Really a simulation game A thought-experiment in mathematical terms ► Is it possible to create “life” using a very simple mathematical model? ► What sort of things might this life do?
Game of Life “Rules” ► The game is played on a grid of squares In principal, this grid extends infinitely in all directions ► Each cell is either alive (X) or dead ( ) ► There are five living cells in this grid XX XX X
Game of Life “Rules” ► Game is played over several generations ► The rules govern how the current population survives to the next generation ► Each cell (living and dead) is considered We look at the eight surrounding cells to determine its fate XX XX X
Game of Life “Rules” ► Live cells: If a live cell has 0 or 1 neighbours it dies If it has 2 or 3 neighbours it survives If it has > 3 neighbours it dies ► Dead cells: If a dead cell has exactly three neighbours, they breed and it becomes alive XX XX X
Game of Life “Rules” ► Live cells: If a live cell has 0 or 1 neighbours it dies If it has 2 or 3 neighbours it survives If it has > 3 neighbours it dies ► Dead cells: If a dead cell has exactly three neighbours, they breed and it becomes alive XX XX X So, what will happen here?
Game of Life “Rules” ► Live cells: If a live cell has 0 or 1 neighbours it dies If it has 2 or 3 neighbours it survives If it has > 3 neighbours it dies ► Dead cells: If a dead cell has exactly three neighbours, they breed and it becomes alive XX X XX
Game of Life “Rules” ► Live cells: If a live cell has 0 or 1 neighbours it dies If it has 2 or 3 neighbours it survives If it has > 3 neighbours it dies ► Dead cells: If a dead cell has exactly three neighbours, they breed and it becomes alive XX X XX What about the next generation?
Termination ► The game continues until: the population stabilizes or; they all die or; they get into oscillations. XXX X X X An oscillator with period 2
Game of Life - Example ► The project called ConwayLife is an implementation of Conway’s Game of Life The simulation happens in LifeBoard.cpp ► The game loop is in lifemain.cpp ► You can load up different starting patterns from lifemain.cpp Pattern files end in.life
Game of Life - Tasks 1. Have a play with the system and look at the various patterns provided 2. Use OpenMP to speed up run_one_generation() in LifeBoard.cpp What is the best speed you can achieve?