Recently I found some code that is very interesting to me, but I can't properly understand it, so can someone please explain it to me?
It's Conway's Game of Life. I think this row can be like a question and 1 meaning true and 0 meaning false; is that correct? But why is there no bool?
void iterGen(int WIDTH, int HEIGHT, char curMap[WIDTH][HEIGHT])
{
int i, j;
char tempMap[WIDTH][HEIGHT];
for (i = 0; i < WIDTH; i++)
{
for (j = 0; j < HEIGHT; j++)
{
int neighbors = 0;
neighbors += curMap[i+1][j+1] == '*' ? 1 : 0;
neighbors += curMap[i+1][j] == '*' ? 1 : 0;
neighbors += curMap[i+1][j-1] == '*' ? 1 : 0;
neighbors += curMap[i][j+1] == '*' ? 1 : 0;
neighbors += curMap[i][j-1] == '*' ? 1 : 0;
neighbors += curMap[i-1][j+1] == '*' ? 1 : 0;
neighbors += curMap[i-1][j] == '*' ? 1 : 0;
neighbors += curMap[i-1][j-1] == '*' ? 1 : 0;
if (curMap[i][j] == ' ')
{
tempMap[i][j] = neighbors == 3 ? '*' : ' ';
}
else if (curMap[i][j] == '*')
{
tempMap[i][j] = neighbors < 2 || neighbors > 3 ? ' ' : '*';
}
}
}
for (i = 0; i < WIDTH; i++)
{
for (j = 0; j < HEIGHT; j++)
{
curMap[i][j] = tempMap[i][j];
}
}
}