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,
- A live cell with fewer than two live neighbors dies.
- A live cell with more than three live neighbors dies.
- A live cell with two or three live neighbors continues to live.
- A dead cell with three live neighbors becomes a live cell.
Please consider the below figure which gives you intuition about the game implementation.
Results,
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).
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