I am not sure on how to code this program. Anyone have any ideas on how I could implement this in C++? I am a bit new to C++ so nothing too complicated would be preferred.

2. game_of_life

What is The Game of life?

Not to be confused with Hasbro's The Game of Life, this problem refers to British mathematician John Conway's famous cellular automation. The term 'cellular automation' refers to a space (in this case a grid) of cells, which continually transform themselves to create new patterns and states, based on the states of neighboring cells, by following a discrete set of mathematical rules. The simulation models cells living, dying, and multiplying over multiple generations.

The Rules

Any live cell with fewer than two live neighbors dies (as if by underpopulation).

Any live cell with more than three live neighbors dies (as if by overpopulation/overcrowding).

Any live cell with two or three live neighbors lives, unchanged, to the next generation.

Any dead cell with exactly three live neighbors will come to life (as if by reanimation or birth).

Neighbors refer to the eight cells adjacent to any given cell in a grid, with the exception of border cells.

The Assignment

For this assignment, we are asking you to implement Conway's Game of Life using a two-dimensional array as a grid in which to store the cells. Live cells are denoted as * characters, dead cells are denoted by the . character.

Input

As input, you will be given a line containing the number of rows, number of columns, and number of generations to simulate in the form m n g followed by m lines containing the initial state of the grid. 3 <= m,n <= 20 and 0 <= g <= 50

For example, a 4 x 5 grid on which 7 generations of life should be simulated, would be given as follows:

4 5 7

. * * . .

. * . . .

* * * . *

. . . . *

You should store this initial grid state in a multidimensional array as discussed in class.

Your Task

The initial state (generation 0) stored in a grid.

. * * . .

. * . . .

* * * . *

. . . . *

You should then compute the next generation (generation 1) by applying the rules to the previous generation grid (generation 0 in this case).

The state of the grid after computing generation 1 should be as follows:

. * * . .

. . . * .

* * * * .

. * . * .

Important Note: "[Generation n] is created by applying the [...] rules simultaneously to every cell in [generation n-1] — births and deaths happen simultaneously" (Wikipedia). This means that when applying rules to n-1 to compute/create n, you should at no point change values in n-1, only observe them. Only after n has been seeded should you change n-1.

Repeat the above process g times until your grid is in its final state. This means that if you receive a g = 0, your initial state and final state would be the same.

Output

Your output should be the final state of the grid after g generations printed to std::cout in the format above.

Note: Your printed grid should contain no trailing whitespace at the end of each row.