Reddit

Game of Life in C++

The Game of Life is an infinite two-dimensional rectangular grid of cells,(cellular automata), where evolution is determined by its initial state. The game was invented by John Horton Conway. Each individual cell of the board can be either alive or dead. Each game move, also known as a generation, involves a change in each cell’s status based on the conditions of its eight neighbors. Cells that touch another cell in a horizontal, vertical, or diagonal direction are said to be that cell’s neighbors.

The first generation is the initial pattern. Updated of the grid occur simultaneously affecting all cells. The next generation is a result of applying the rules concurrently to every cell on the game board. After then, new generations are produced by iteratively applying the rules.

The rules and implementation (please see my implementation in C++ on my GitHub) can be given as follows,

Please consider the below figure which gives you intuition about the game implementation.

by author

Results,

by author

Depending on how you define the initial pattern, the population generates in different directions. There are shapes that, do not change shape. There is also a shape that can move or oscillate. I really recommend you to take a look at an impressive free book, which describe all these kind of mechanism of shape (see also here).

Stable
Oscillating
Moving (all Wikipedia)

In order to use Eigen C++ library, visit the website. Download the Eigen repository to your favorite location on your machine and (for Linux users) create the soft link.

git clone https://gitlab.com/libeigen/eigen.git
sudo ln -s /usr/include/eigen3/Eigen /usr/local/include/
/usr/include/eigen3/Eigen <-- location of your cloned library

Thank you for reading

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store