Hi all!
You've probably all heard of some rendition of the game of life and now it's my turn to try and code it.:-/
Anyway, everything is fine up until my Life function(this is the function where I put all the "rules" of life). My output is now completely blank. I checked halfway through making all my if statements and half of the 1st row and half of the 2nd row was completely filled with *'s. After I finished writing my if statements, everything was blank. I knew something was wrong halfway through but I can't find a mistake in my logic. So, I need a fresh pair of eyes. lol! What am I doing wrong???
Below is my Life function code:
void Life(bool bacteria[][COL])
{
bool nextGenbacteria[ROW][COL];
int neighbors=0;
int neighborsDead=0;
for(int row=0;row<ROW;row++)
{
for(int col=0;col<COL;col++)
{
if(bacteria[row][col]==true&&bacteria[row][col-1]==true)
{
neighbors++;
}
if(bacteria[row][col]==true&&bacteria[row][col+1]==true)
{
neighbors++;
}
if(bacteria[row][col]==true&&bacteria[row-1][col]==true)
{
neighbors++;
}
if(bacteria[row][col]==true&&bacteria[row+1][col]==true)
{
neighbors++;
}
if(bacteria[row][col]==true&&bacteria[row+1][col+1]==true)
{
neighbors++;
}
if(bacteria[row][col]==true&&bacteria[row-1][col-1]==true)
{
neighbors++;
}
if(bacteria[row][col]==true&&bacteria[row+1][col-1]==true)
{
neighbors++;
}
if(bacteria[row][col]==true&&bacteria[row-1][col+1]==true)
{
neighbors++;
}
if(bacteria[row][col]==false&&bacteria[row][col-1]==true)
{
neighborsDead++;
}
if(bacteria[row][col]==false&&bacteria[row][col+1]==true)
{
neighborsDead++;
}
if(bacteria[row][col]==false&&bacteria[row-1][col]==true)
{
neighborsDead++;
}
if(bacteria[row][col]==false&&bacteria[row+1][col]==true)
{
neighborsDead++;
}
if(bacteria[row][col]==false&&bacteria[row+1][col+1]==true)
{
neighborsDead++;
}
if(bacteria[row][col]==false&&bacteria[row-1][col-1]==true)
{
neighborsDead++;
}
if(bacteria[row][col]==false&&bacteria[row+1][col-1]==true)
{
neighborsDead++;
}
if(bacteria[row][col]==false&&bacteria[row-1][col+1]==true)
{
neighborsDead++;
}
if(neighbors<2||neighbors>3)
{
nextGenbacteria[row][col]=false;
}
if(neighbors==2||neighbors==3)
{
nextGenbacteria[row][col]=true;
}
if(neighborsDead==3)
{
nextGenbacteria[row][col]=true;
}
if(neighborsDead!=3)
{
nextGenbacteria[row][col]=false;
}
}
}
for(int x=0;x<ROW;x++)
{
for(int y=0;y<COL;y++)
{
bacteria[x][y]=nextGenbacteria[x][y];
}
}
}
And attached is a .pdf file of my assignment.(I just noticed the nifty manage attachments button):$