Hey, I have an assignment called the Game of Life. If you haven't heard of it, feel free to look it up. Anyway, the problem I am having is the algorithm I have to compute if the living cell has any neighbors is not producing anything. I know that the code is a little redundant but if you have any suggestions, please help.
This code basically goes through the array and adds up all the neighbors and if they are less than 2 or more than 3, then the current node is dead(i.e. 0)
Here is the code:
Code:void liveon(int g1[][22],int g2[][22]) { for(int r=0;r<22;r++) for(int c=0;c<22;c++) while(g1[r][c]=1) { if(g1[r-1][c-1]+g1[r-1][c]+g1[r-1][c+1]//top of block + g1[r][c-1]+g1[r][c+1] //middle of block + g1[r][c]+g1[r][c]+g1[r][c]<2 //bottom of block || g1[r-1][c-1]+g1[r-1][c]+g1[r-1][c+1] //top of block + g1[r][c-1]+g1[r][c+1] //middle of block + g1[r+1][c-1]+g1[r+1][c]+g1[r+1][c+1]>3) // bottom g1[r][c]=0; } //copy to second array }