Description

In this assignment, you will code a simulation called "Game of Life". It is a very famous 'game' and the formed the basis of an entire field of simulation models called "cellular automata". Before continuing reading this assignment, I suggest you read a bit more about Game of Life at:

https://en.wikipedia.org/wiki/Conway's_Game_of_Life

or

http://www.math.com/students/wonders/life/life.html

(the latter also has a nice Java applet of the game that is quite fun to play with!)

You should now know about the basics of game of life: it is a 'simulation' of cells that are 'dead' or 'alive' in discrete time steps, at every step all of the cells will get computed a new value in parallel (i.e., based on the values of the neighbours at the *previous* time step - this will require a little bit of thinking!), and the rules to determine if a cell is dead or alive are:

  • Any live cell with fewer than two live neighbours die, as if caused by under population.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any live cell with more than three live neighbours dies, as if by overpopulation.
  • Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

You now need to write a program that reads in an initial 'board' configuration, and then performs a specified number of simulations.

As always, try and keep your program clean, modular, and only allocate as much memory as you need (using malloc).

Input

The first line will specify 3 numbers:

  • the number of rows
  • the number of columns
  • the number of steps you need to simulate

The remainder of the input file comprises the initial configuration, which will have exactly the specified number of rows and columns. Dead cells are indicated with '.' while live cells are marked with 'X'.

Output

As output, you will need to write the board configuration that results from the specified number of simulations, in exactly the same format as you read the input.

Sample Input

6 6 20
.X...X
X.X.X.
X...X.
X..XX.
..XX.X
...X.X

Sample Output

...X..
..X.X.
..X.X.
...X..
......
......
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.