Skip to content

In this project, we will implement Conways's Game of Life, and attempt to make your implementation as fast as possible

Notifications You must be signed in to change notification settings

maxrantil/game_of_life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game of Life

In this project, we will implement Conways's Game of Life, and attempt to make the implementation as fast as possible

The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. (Source: Wikipedia)

Rules of the Game of Life

The universe of the Game of Life is an infinite, two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead. Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

• Any live cell with two or three live neighbors survives.

• Any dead cell with three live neighbors becomes a live cell.

• All other live cells die in the next generation. Similarly, all other dead cells stay dead. (Source: Wikipedia)

To make the program just run the Makefile

$ make

Usage:

$ ./life <map> <iterations>

e.g.

$ ./life states/tests/diehard 1000

the last locations of the cells after 1000 iterations will be printed out.

Optimization

Our biggest optimization was to stop the iteration if we notice that the same patterns repeat themselves. There is a pattern called Blinkers with just two different patterns that will repeat and many maps get to that point after a while. We check that with the help of bitwise operations and will turn on specific bits to check if the cell is alive or dead and what the previous stage was. We also use it for knowing what the upcoming state will be when we check the neibours of the cells. (look at the file game_of_life/sources/iterate_opti.c that file and game_of_life/sources/game_of_life.c does all the action) The file game_of_life/sources/iterate_slow.c will have less operations and will be faster on maps that will continue to the end of the iterations you ask for. To compile that use:

Usage:

$ ./life_opti <map> <iterations>

GUI Bonus

Usage:

$ ./life_gi states/tests/diehard
'r' = reset
'esc' = exit
'space' = pause
(you can draw with the mouse on the maps!)

Usage:

$ ./life_gi states/big_map

Usage:

$ ./life_gi states/tests/dinnertable

Usage:

$ ./life_gi states/fullscreen.txt

examples from Wikipedia

Pulsar

Penta-decathlon

Glider

Light-weight spaceship

Heavy-weight spaceship

About

In this project, we will implement Conways's Game of Life, and attempt to make your implementation as fast as possible

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published