I am stuck on how to exactly do this problem if anyone could offer me any help with either a worked out solution or just some pseudocode that would be great. Here are the rules and information about the assignment below.

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.

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.

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.

Recommended Answers

All 2 Replies

So that's one well worn code base. I mean if I look at https://rosettacode.org/wiki/Conway%27s_Game_of_Life I see over 100 implementations in 99 languages.

In your case you may wish to start with an array, fill it with the starting data or states then code to follow those rules and iterate (loop) over the rule the number of times you wish.

Finally you exit that loop and print out your array.

In your case you may wish to start with an array, fill it with the starting data or states then code to follow those rules and iterate (loop) over the rule the number of times you wish.

You can't do this with one array. You need a second array to hold the new values because the alogorithm requires the original values until the whole grid has been evaluated.

commented: You're right. But be careful as it can get out of control as some do with cats or other pets. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.