The game of life

Programming

  1. The actual size of the population (n and m), as well as the maximum number of generations, can either be declared as global constants, or entered by the user and passed as parameters to various functions (in which case the capacity of the array has to be declared as a global constant).

  2. The array’s entries can be either of type int, char or bool.

  3. The program has to display the initial population, and the population after each generation (giving the generation number, starting from 1), until either the whole population dies, or until you reach the max number of generations.

  4. Bonus marks will be added if the execution stops if the population reaches a stable state.

  5. Please include two alternative techniques to initialize the population. In the first one, the cells are entered one after the other by the user, as a sequence of characters (‘0’ for dead and ‘1’ for live). In the second one, the cells are generated randomly, according to a given density. For example, if the required density is 30%, then for each cell a random number between 1…100 is generated. If the number is <=30, the cell is alive, otherwise the cell is dead. When marking the assignments, we will choose one or the other of the initialization techniques.

Include functions such as:
void initialize(…) // initialize the nxm population
void initialize2(…, int density) // initialize given a density
int countNeighbours (…, int x, int y) // counts live neighbours of cell x,y
bool allDead(…) // checks if the population is dead
void reproduce(…) // produce the next generation
void print(…) // print a population

Make your program simple and elegant!!! And Include comments and use proper indentation

If you check on internet, you will find interesting patterns that make the population go into cycles, or that die after a number of generations. You can test your program with these patterns! Have fun!

Use the following skeleton for the program

. // Global constants
const int MAXGEN = 3; // maximum no. of generations
const int n = 10 ; // no. of rows
const int m = 10 ; // no. of colums

int main(){
int grid[n][m];
initialize(grid); // you should call either initialize, or initialize2
cout << “Initial population = \n”;
print(grid);
gen = 1;
print (grid);
while (gen <= MAXGEN && !allDead(grid)){
cout << "gen = " << gen;
reproduce(grid); // will call the function countNeighbours for each cell
print (grid);
gen++;
}
}

can anyone solve this please?