I'm writing a program of Conway's Game of Life. I think I've figured out most of it but there something wrong with the rules I've set up
for(row=0;row<20;row++) {
for(col=0;col<21;col++) {
n=0;
if (a[row][col]=='*') {
if(a[row-1][col-1]=='*') {
n++;
}
if(a[row-1][col]=='*') {
n++;
}
if(a[row-1][col+1]=='*') {
n++;
}
if(a[row][col-1]=='*') {
n++;
}
if(a[row][col+1]=='*') {
n++;
}
if(a[row+1][col-1]=='*') {
n++;
}
if(a[row+1][col]=='*') {
n++;
}
if(a[row+1][col+1]=='*') {
n++;
}
}
if(n==2 || n==3) {
b[row][col]='*';
}
}
}
The code should replace the current value in the array with a * if two or three of its surrounding characters are also a *. the * is placed into a second array and after all rules are completed the b array is copied into the a array and it starts over.