Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im totally stuck on this problem and have just been looking at this for the past

ID: 3867088 • Letter: I

Question

Im totally stuck on this problem and have just been looking at this for the past couple days and would really appreciate some help, thanks!

Game of Life program**

The game of life is a computer simulation of the life and death events of a population of organisms. This program will determine the life, death, and survival of bacteria from one generation to the next, assuming the starting grid of bacteria is generation zero (0). Each cell has a total of up to 8 neighbors, including the 4 immediately adjacent cells and the 4 diagonal cells. The rules for the creation of each cell in the next generation are as follows:

If the cell is currently empty:

If the cell has exactly three living neighbors, it will come to life in the next generation.

If the cell has any other number of living neighbors, it will remain empty.

If the cell is currently living:

If the cell has one or zero living neighbors, it will die of loneliness in the next generation.

If the cell has four or more living neighbors, it will die of overcrowding in the next generation.

If the cell has two or three neighbors, it will remain living.

All births and deaths occur simultaneously (make sure you don't get this one wrong!).

Your task is to write a program that plays the game of life. The size of the grid will be a 20 x 20 square. Your solution must use a 20 X 20 two-dimensional array. Don't declare a bigger array! It is permissible, of course, to use a second array of the same size if you find it convenient or helpful to do so.

A "Game_of_life" class (ADT) set-up and implementation is possible but is not required. DO NOT use pointers or vectors for this project.

To begin the "game of life" your program must initialize the grid with generation 0 which should now include live cells based on the coordinates provided in the bacteria.txt file. Next your program must use the criteria provided above and allow life to proceed for 5 generations. Finally, your program should display the life forms for the fifth generation on the screen, using asterisks (*) to represent live bacteria on a grid, along with the following statistical information:

The total number of living bacteria cells in row index 10.

The number of dead bacteria cells in row index 10.

The number of living bacteria cells in column index 10.

The number of dead bacteria cells in column index 10.

The number of living bacteria cells in the entire board.

The number of dead bacteria cells in the entire board.

*note ...row 10 and column 10 refers to the actual row and column indexes in the 20 x 20 two-dimensional array

bacteria.txt

0   0
   0   3
   0   5
   0   9
   0 19
   1   6
   1 14
   1 16
   2   4
   2   7
   2 11
   2 14
   2 15
   2 16
   2 18
   3   2
   3   5
   3   9
   3 10
   3 17
   3 19
   4   0
   4   3
   4   5
   4   9
   5   2
   5   3
   5   5
   5 15
   5 16
   5 17
   6   5
   6   6
   6 10
   6 11
   6 13
   6 14
   6 17
   6 18
   7   6
   7   8
   7 14
   7 16
   8   1
   8   5
   8   8
   8 10
   8 17
   9   3
   9   4
   9   6
   9   7
10   0
10   9
10 19
11   1
11   2
11   3
11   5
11   7
11   8
11 14
11 17
11 19
12   4
12   5
12   6
12   8
13   0
13   1
13   7
13 10
13 11
13 14
13 15
13 16
13 17
13 18
14   2
14 11
14 13
14 15
14 17
14 19
15 11
15 13
15 18
16   1
16   2
16   5
16   8
16 16
17   5
17   6
18   6
18 16
18 18
19   0
19   3
19   4
19   7

Explanation / Answer

#include<iostream>

#include<fstream>

#include<iomainp>

#include<cassert>

using namespace std;

const int size-20;

int main()

{

bool life[size][size];

int row ,col;

//intialize array

for(int row=0;row<size;row++)

{

for(int col=0;col<size;col++)

{

life[row][col]=false;

}

}

//print contents of array after intilization

cout<<"01234567890123456789"<<endl;

for(int row=0;row<size;row++)

{

cout<<setw[2]<<row;

for(int col=0;col<size;col++)

{

cout<<life[row][col];

}

cout<<endl;

//readGrid
ifstream infile("lifedata.txt");
assert(infile);
infile >> row >> col;
while (infile)
{
life[row][col] = true;
infile >> row >> col;
}
infile.close();

//print contents of two-dimensional array

cout << " 01234567890123456789" << endl;
for (int row = 0; row < SIZE; row++)
{
cout << setw(2) << row;
for (int col = 0; col < SIZE; col++)
{
if (life[row][col])
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
system ("PAUSE");
return 0;
}


Input:

0 0
0 5
0 9
0 19
1 6
1 14
1 16
2 4
2 7
2 11
2 14
2 15
2 16
2 18
3 2
3 5
3 9
3 10
3 17
3 19
4 0
4 3
4 5
4 9
5 2
5 3
5 5
5 15
5 16
5 17
6 5
6 6
6 10
6 11
6 13
6 14
6 17
6 18
7 6
7 8
7 14
7 16
8 1
8 5
8 8
8 10
8 17
9 3
9 4
9 6
9 7
10 0
10 9
10 19
11 1
11 2
11 3
11 5
11 7
11 8
11 14
11 17
11 19
12 4
12 5
12 6
12 8
13 0
13 1
13 7
13 10
13 11
13 14
13 15
13 16
13 17
13 18
14 2
14 11
14 13
14 15
14 17
14 19
15 11
15 13
15 18
16 1
16 2
16 5
16 8
16 17
17 5
17 6
18 6
18 16
18 18
19 0
19 3
19 4
19 7

Output:
01234567890123456789
0
1 * *
2 * * *** *
3 * **** *
4 * * * **
5 * * ***** *
6 ** * * *** *
7 * *** * *
8 ****
9 * ******
10* * *
11 * * ** *
12** **** ***
13 * *** ** *
14 * * * ***
15 ** *** ** **
16 * * **
17
18
19
Total alive in row 10 = 3
Total alive in col 10 = 1
Total alive = 95