Game of Life, Determining Next Gen Help / Question

Pages: 12
I am currently working on a Game of Life Program for my C++ class and had a bit of an issue, I am trying to update and generate new grids for the next generation but am a bit stuck. For my spec my instructor wants me to use the class I have come up with but we cannot use any arrays in our main client program. I am not sure what other alternative we can use that do not include arrays, I have done some research on this topic and most examples are just plain arrays.

Here is my function for determining the next gen of our Game of Life along with my class. I can provide a data file or output if necessary.

boolmatrix.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef LIFE_H
#define LIFE_H

#include <iostream>
#include <iomanip>
#include <cassert>
#include <fstream>

using namespace std;

class boolMatrix
{
public:
    static const int NUM_ROWS = 20; //Static variable declaring row size
    static const int NUM_COLS = 20; //Static variable declaring column size
    boolMatrix();   //A default constructor
    void set(int row,int col, bool val);
    void print() const; //observers
    bool get(int row,int col) const;
    int totalCount()const;
    int rowCount(int row)const;
    int colCount(int col)const;
    int neighborCount(int row, int col)const;
private:
    bool matrix[NUM_ROWS][NUM_COLS];

};

#endif 


Function for determining nextGen, in main.cpp

1
2
3
4
void determineNextGeneration(/*inout*/ boolMatrix& life)
{

}
Last edited on
It looks like he wants you to do this:

1
2
3
4
5
6
void determineNextGeneration(/*inout*/ boolMatrix& life)
{
    boolMatrix b; // I'm assuming ctor sets all elements to false (not alive)
    // go through life matrix, setting cells in b to true if that cell will be alive next round
    // then copy b back to life
}

If we wanted to avoid the copy at the end, we could switch back and forth between two life matrices.
Yeah something like that:

He also points out the rules for each gen:

-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. This point is critical to the correct result.

I'm assuming we are then creating a series of if and else statements, for the cell will I have to declare it as a separate integer? That is one aspect i'm confused on as well.

Im assuming something like this for the first one since we cannot use arrays:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void determineNextGeneration(/*inout*/ boolMatrix& life)
{
    boolMatrix b; 

    int neighbors=0;
    for (int row=0;row<boolMatrix::NUM_ROWS;row++) 
//boolMatrix::NUM_ROWS since it is declared as static const in class
    {
        for (int col=0;col<boolMatrix::NUM_COLS;col++)
        {

            if (neighbors<=1)
                b.get(row, col)=false;
            if (neighbors>=4)
                b.get(row,col)=false;
            if (neighbors==2)
                b.get(row,col)=true;
            if (neighbors==3)
                b.get(row,col)=true;

        }
    }

}

Last edited on
Yeah, except you need an outer if to test if it's alive or not since the rules are different, and then an inner if. Also, you need to use set() to set a value. So, assuming that b has been initialized to false by the ctor, we only need to set the true ones.

1
2
3
4
5
6
7
8
9
10
11
12
13
// I forget what your neighbor-counting interface looks like, but something like:
int count = count_neighbors(life, row, col); 

if (life.get(row, col)) // is alive
{
    if (count > 1 && count < 4)
        b.set(row, col, true);
}
else
{
    if (count == 3)
        b.set(row, col, true);
}

Last edited on
Here is the neighborCount interface:

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

int boolMatrix::neighborCount(int row, int col)const
{
    assert(row>= 0 && row < NUM_ROWS && col >= 0 && col < NUM_COLS);
    int count = 0;

    if(row > 0)
        count += get(row - 1, col);
    if(row < NUM_ROWS - 1)
        count += get(row + 1, col);
    if(col > 0)
        count += get(row, col - 1);
    if(col < NUM_COLS - 1)
        count += get(row, col + 1);

    return count;
}



set function *B is indeed initialized to false*

1
2
3
4
5
6
7

void boolMatrix::set(int row,int col, bool val)
{
    assert(row >= 0 && row < NUM_ROWS && col >= 0 && col < NUM_COLS);
    matrix[row][col] = val;
}


Will update and work on this function, I'll keep you updated.
Last edited on
So you would use neighborCount like this in that code I showed above:

 
    int count = life.neighborCount(row, col);

And in neighborCount remember that you need to count the diagonal directions, too.

1
2
3
    if(row > 0 && col > 0)
        count += get(row - 1, col - 1);
    // etc... 

I had one question dutch, for testing if its alive or not you meant to have the conditional statements still inside the for loop correct?



P.S: I included the conditional statements into the for loop and for some reason when I enter two generations in my main.cpp it overwrites both of my grids and outputs blank, I also took into consideration about updating the neighborCount to do diagonals too.

Can provide main.cpp code if needed

OUPUT:

Enter number of generations: 2

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


Total alive in matrix: 0
Total alive in row 10: 0
Total alive in column 10: 0

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


Total alive in matrix: 0
Total alive in row 10: 0
Total alive in column 10: 0


Process returned 0 (0x0) execution time : 1.571 s
Press any key to continue.


Last edited on
If the very first picture is blank maybe the data isn't being read in properly.
Either post everything here including input or post a link so I can run it.
boolMatrix.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef LIFE_H
#define LIFE_H

#include <iostream>
#include <iomanip>
#include <cassert>
#include <fstream>

using namespace std;

class boolMatrix
{
public:
    static const int NUM_ROWS = 20; //Static variable declaring row size
    static const int NUM_COLS = 20; //Static variable declaring column size
    boolMatrix();   //A default constructor
    void set(int row,int col, bool val);
    void print() const; //observers
    bool get(int row,int col) const;
    int totalCount()const;
    int rowCount(int row)const;
    int colCount(int col)const;
    int neighborCount(int row, int col)const;
private:
    bool matrix[NUM_ROWS][NUM_COLS];

};

#endif



BoolMatrix.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
#include <iomanip>
#include <cassert>
#include <fstream>
#include "boolmatrix.h"

using namespace std;

boolMatrix::boolMatrix()
{
    //initialize array - HINT source code below should be an initialize function
    for (int row = 0; row < NUM_ROWS; row++)
    {
        for (int col = 0; col < NUM_COLS; col++)
        {
            matrix[row][col] = false;
        }
    }
}

void boolMatrix::set(int row,int col, bool val)
{
    assert(row >= 0 && row < NUM_ROWS && col >= 0 && col < NUM_COLS);
    matrix[row][col] = val;
}

void boolMatrix::print() const
{
    //print contents of array after initialization - HINT source code below should be a print function
    //	cout << "  01234" << endl;
     cout << "  ";
     for(int col = 0; col < NUM_COLS; col++)
     {
         cout << col % 10;
     }
     cout << endl;
    for (int row = 0; row < NUM_ROWS; row++)
    {
        cout << setw(2) << row % 25;
        for (int col = 0; col < NUM_COLS; col++)
        {
           if (matrix[row][col])
            {
                cout << "*";
            }
            else
            {
                cout << " ";
            }
        }
        cout << endl;
    }

    cout << endl;
}

bool boolMatrix::get(int row, int col) const
{
    assert(row>= 0 && row < NUM_ROWS && col >= 0 && col < NUM_COLS);
    return matrix[row][col];
}

int boolMatrix::totalCount()const
{
    int count = 0;
    for(int row = 0; row < NUM_ROWS; row++)
    {
        for(int col = 0; col < NUM_COLS; col++)
        {
            if(matrix[row][col])
                count++;
        }
    }
    return count;
}

int boolMatrix::rowCount(int row)const
{
    //assert
    assert(row >= 0 && row < NUM_ROWS);
    int count = 0;

    for(int col = 0; col < NUM_COLS; col++)
    {
        if(matrix[row][col])
                count++;
    }
    return count;
}

int boolMatrix::colCount(int col)const
{
    //assert
    assert(col >= 0 && col < NUM_COLS);
    int count = 0;

    for(int row = 0; row < NUM_ROWS; row++)
    {
        if(matrix[row][col])
                count++;
    }
    return count;
}

int boolMatrix::neighborCount(int row, int col)const
{
    assert(row>= 0 && row < NUM_ROWS && col >= 0 && col < NUM_COLS);
    int count = 0;

    if(row > 0)
        count += get(row - 1, col);

    if(row < NUM_ROWS - 1)
        count += get(row + 1, col);

    if(col > 0)
        count += get(row, col - 1);

    if(col < NUM_COLS - 1)
        count += get(row, col + 1);

    if(row > 0 && col > 0)
        count += get(row - 1, col - 1);

    if(row < 0 && col < 0)
        count += get(row + 1, col + 1);

    return count;
}



Main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <iomanip>
#include <cassert>
#include <fstream>
#include "boolmatrix.h"

using namespace std;

void readGrid(/*out*/ boolMatrix& life);
void getGenerations(/*out*/ int& numGenerations);
void determineNextGeneration(/*inout*/ boolMatrix& life);
void determineFateOfSingleCell(/*in*/ const boolMatrix& life,/*out*/ boolMatrix& life2,/*in*/int row,/*in*/ int col);
void printResults(/*in*/ const boolMatrix& life);

int main()
{
    boolMatrix life;    //Used for file reading

    int numGenerations;

   /* life.print();       //Normal ADT Grid Display */

    readGrid(life);     //ADT / File Read Display

    getGenerations(numGenerations);

    for (int count = 0; count < numGenerations; count++)
    {
        determineNextGeneration(life);
        printResults(life);
    }



    //*NOTE: MULTI LINE COMMENTS ARE CLASS TESTING FUNCTIONS*


 /*   //populate a bool array using rand values for cell coordinates or positions
    for (int i = 0; i < 50; i++) {
        life.set(rand() % 20, rand() % 20, true);
    } */

   // cout << life.get(0,0) << endl;

   /* for (int row = 0; row < boolMatrix::NUM_ROWS; row++) {
    	for (int col = 0; col < boolMatrix::NUM_COLS; col++) {
    		cout << life.neighborCount(row, col); //calling an important function to look around a cell
    	}
    	cout << endl;
    } */

}

void readGrid(boolMatrix& life)
{
    int row, col;
    //readGrid - HINT source code below should be a read or get_input function
    ifstream infile("lifedata.txt");

    infile >> row >> col;
    while (infile)
    {
        //matrix[row][col] = true;
        life.set(row,col,true); //a setter class member function is needed here
        infile >> row >> col;
    }
    infile.close();
}

void getGenerations(/*out*/ int& numGenerations)
{
    cout << "Enter number of generations: ";
    cin >> numGenerations;
    cout << endl;
}

void printResults(/*in*/ const boolMatrix& life)
{
    life.print(); //calling the class print member function
    cout << endl;

    //calling three more class member functions
    cout<<"Total alive in matrix: " << life.totalCount()<< endl;    //Determines total alive
    cout<<"Total alive in row 10: " << life.rowCount(10) << endl;   //Determines total alive in specific row
    cout<<"Total alive in column 10: " << life.colCount(10) << endl;    //Determines total alive in specific column

    cout << endl;

}

void determineNextGeneration(/*inout*/ boolMatrix& life)
{
    boolMatrix b;

    for(int row=0;row<boolMatrix::NUM_ROWS;row++)
    {
        for (int col=0;col<boolMatrix::NUM_COLS;col++)
        {
            int count = b.neighborCount(row,col);

            if(b.get(row,col))
            {
                if(count > 1 && count < 4)
                    b.set(row,col,true);
            }

            else if(b.get(row,col))
            {
                if(count == 3)
                    b.set(row,col,true);
            }

            else if(b.get(row,col))
            {
                if(count == 1 || count == 0)
                    b.set(row,col,false);
            }

            else if(b.get(row,col))
            {
                if(count == 4 || count > 4)
                    b.set(row,col,false);
            }

            else if(b.get(row,col))
            {
                if(count == 2 || count == 4)
                    b.set(row,col,true);
            }

        }
    }

    life = b;
}


lifedata.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
You've overcomplicated it. And the count needs to be from life, not b.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void determineNextGeneration(/*inout*/ boolMatrix& life)
{
    boolMatrix b;

    for(int row=0;row<boolMatrix::NUM_ROWS;row++)
    {
        for (int col=0;col<boolMatrix::NUM_COLS;col++)
        {
            int count = life.neighborCount(row,col);

            if(b.get(row,col))
            {
                if(count > 1 && count < 4)
                    b.set(row,col,true);
            }
            else
            {
                if(count == 3)
                    b.set(row,col,true);
            }
        }
    }

    life = b;
}

And you're missing two of the diagonal corners.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int boolMatrix::neighborCount(int row, int col)const
{
    assert(row>= 0 && row < NUM_ROWS && col >= 0 && col < NUM_COLS);
    int count = 0;

    if(row > 0)
        count += get(row - 1, col);

    if(row < NUM_ROWS - 1)
        count += get(row + 1, col);

    if(col > 0)
        count += get(row, col - 1);

    if(col < NUM_COLS - 1)
        count += get(row, col + 1);

    if(row > 0 && col > 0)
        count += get(row - 1, col - 1);

    if(row > 0 && col < NUM_COLS - 1)
        count += get(row - 1, col + 1);

    if(row < NUM_ROWS - 1 && col > 0)
        count += get(row + 1, col - 1);

    if(row < NUM_ROWS - 1 && col < NUM_COLS - 1)
        count += get(row + 1, col + 1);

    return count;
}

Is there a simpler way to go about finding the remaining corners also when I run the program to get the first grid out put I get,

Enter number of generations: 1

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


Total alive in matrix: 81
Total alive in row 10: 3
Total alive in column 10: 5


Process returned 0 (0x0) execution time : 1.331 s
Press any key to continue.

---------------------------------------------

instead of:

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 = 4
Total alive = 100



Could it be related to my neighborCount?
I think that's just because you generate the next generation before you print the grid. Put the print call before the generate call.
We are very very close

After modifying it to your suggestion:

Enter number of generations: 1


  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 column 10: 4
Total alive in matrix: 101

  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 column 10: 5
Total alive in matrix: 81


Process returned 0 (0x0)   execution time : 1.561 s
Press any key to continue.


-----------------------------------------------------------------------

Now I just need to see whats causing the second grid to not match this output along with stats:


Enter number of generations: 2

(ORIGINAL GRID) GAME OF LIFE BEGINS STATISTICS

  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 = 4
Total dead in row 16 = 15
Total dead in col 1 = 16
Total alive = 101
Total dead = 299


The grid after 1 generations have passed.
(GENERATION #1) GAME OF currentgen STATISTICS

  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 = 6
Total dead in row 16 = 18
Total dead in col 1 = 14
Total alive = 113
Total dead = 287


-----------------------------------------------------------------
The goal is to have generation five output this:


The grid after 5 generations have passed.
(GENERATION #5) GAME OF currentgen STATISTICS

  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 dead in row 16 = 16
Total dead in col 1 = 16
Total alive = 95
Total dead = 305


Process returned 0 (0x0)   execution time : 6.920 s
Press any key to continue.

Last edited on
Can you edit your post and put output tags around those grids to retain spacing?
output tags are like code tags except for the word output instead of code.
Or if you use the buttons, it's the one to the right of the code tag <> button.
Last edited on
Fixed :D
If this is supposed to be the first frame then something's wrong with your input data, which clearly has 101 points (101 lines in the text file) and one of them is 0 3, which is not set in this picture. And it says there's only 100 points set.

  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 = 4
Total alive = 100

Is that output just loading the text file by itself? Because on mine it loads the text file (first grid) like its supposed to. I am a bit confused .-.
Last edited on
No, this is from your previous post (which you should also add output tags to, if you can).
You say there that it's supposed to look like that, with 100 points.
This is the intended output for the program:



Enter number of generations: 5

(ORIGINAL GRID) GAME OF LIFE BEGINS STATISTICS

  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 = 4
Total dead in row 16 = 15
Total dead in col 1 = 16
Total alive = 101
Total dead = 299


The grid after 1 generations have passed.
(GENERATION #1) GAME OF currentgen STATISTICS

  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 = 6
Total dead in row 16 = 18
Total dead in col 1 = 14
Total alive = 113
Total dead = 287


The grid after 2 generations have passed.
(GENERATION #2) GAME OF currentgen STATISTICS

  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 = 2
Total alive in col 10 = 6
Total dead in row 16 = 16
Total dead in col 1 = 15
Total alive = 99
Total dead = 301


The grid after 3 generations have passed.
(GENERATION #3) GAME OF currentgen STATISTICS

  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 = 4
Total alive in col 10 = 3
Total dead in row 16 = 18
Total dead in col 1 = 17
Total alive = 97
Total dead = 303


The grid after 4 generations have passed.
(GENERATION #4) GAME OF currentgen STATISTICS

  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 = 5
Total dead in row 16 = 16
Total dead in col 1 = 15
Total alive = 95
Total dead = 305


The grid after 5 generations have passed.
(GENERATION #5) GAME OF currentgen STATISTICS

  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 dead in row 16 = 16
Total dead in col 1 = 16
Total alive = 95
Total dead = 305


Process returned 0 (0x0)   execution time : 6.920 s
Press any key to continue.

In determineNextGeneration, the if that tests if the cell is alive or not needs to test life, not b:

 
            if(life.get(row,col))
Pages: 12