Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Game of Life Help
Post Flair (click to view more posts with a particular flair)
Post Body

Got the bulk done of this game of life assignment, but my cells are wrong and I can't seem to figure out why. The rules are:

  1. any dead cell (0) that has exactly 3 neighboring live cells (1) will become alive
  2. any live cells that have 4 or more neighboring live cells die
  3. any live cells with 2 or 3 neighboring live cells survive another generation
  4. any live cells with 1 or 0 neighboring live cells die

We are not supposed to process the bordering cells. Here is my code for processing the cells:

void generationProcess(int array[][COLS])
{
    int neighborsAlive;

    for(int row = 1; row < 11; row  )
    {
        for(int col = 1; col < 11; col  )
        {
            neighborsAlive = 0;
            for(int i = (row - 1); i <= (row   1); i  )
            {
                for(int j = (col - 1); j <= (col   1); j  )
                {
                    if(i == row && j == col)
                    {
                    }
                    else if(array[i][j] == 1)
                    {
                        neighborsAlive  ;   
                    }
                    else
                    {
                    }   
                }   
            }

            if(array[row][col] == 0 && neighborsAlive == 3)
            {
                array[row][col] == 1;
            }
            else if(neighborsAlive >= 4)
            {
                array[row][col] = 0;    
            }
            else if(neighborsAlive <= 1)
            {
                array[row][col] = 0;    
            }
            else
            {
                if(array[row][col] == 1)
                    array[row][col] = 1;    
            }   
        }   
    }   
}

Here is an example of the first two generations:

    Game of Life
    ------------
    Generation #1

    0  1  2  3  4  5  6  7  8  9 10 11

0   0  0  0  0  0  0  0  0  0  0  0  0  

1   0  0  0  0  1  0  1  0  1  0  0  0  

2   0  0  0  1  0  1  0  1  0  0  0  0  

3   0  0  0  0  0  0  0  0  0  0  0  0  

4   0  0  0  0  1  0  1  0  1  0  0  0  

5   0  0  0  1  0  1  0  1  0  0  0  0  

6   0  1  1  1  1  1  1  1  1  1  1  0  

7   0  0  0  0  1  1  1  1  0  0  0  0  

8   0  0  0  0  1  0  1  0  1  0  0  0  

9   0  0  0  1  0  1  0  1  0  0  0  0  

10  0  0  0  0  1  0  1  0  1  0  0  0  

11  0  0  0  0  0  0  0  0  0  0  0  0  

    Generation #2

    0  1  2  3  4  5  6  7  8  9 10 11

0   0  0  0  0  0  0  0  0  0  0  0  0  

1   0  0  0  0  1  0  1  0  0  0  0  0  

2   0  0  0  0  0  1  0  0  0  0  0  0  

3   0  0  0  0  0  0  0  0  0  0  0  0  

4   0  0  0  0  1  0  1  0  0  0  0  0  

5   0  0  0  0  0  0  0  0  0  0  0  0  

6   0  0  0  1  0  0  0  1  1  1  0  0  

7   0  0  0  0  1  0  1  0  0  0  0  0  

8   0  0  0  0  1  0  1  0  0  0  0  0  

9   0  0  0  1  0  0  0  1  0  0  0  0  

10  0  0  0  0  0  0  0  0  0  0  0  0  

11  0  0  0  0  0  0  0  0  0  0  0  0  

I'm sure it's something stupid, but I can't seem to crack it. One cell for an example, row 1 column 5 should have became a live cell, but it didn't. Any help is appreciated!

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,214
Link Karma
2,190
Comment Karma
6,915
Profile updated: 2 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago