I have done all the code right and stuck with this silly thing: I cannot mange to stop the print when the previous generation is the same as the new...so when the prints pattern is the same as the previous pattern it should stop.
I need to copy the board before calling 'step' and then compare the new and copied boards, and only print if it has changed i need is to create a new variable just like i did board[], then to make a nested loop like the one in print, and inside do newboard[y][x] = board[y][x]
Please help me with this i cannot stop the print it always keep printing. please show me your syntax
void step(int board[][WIDTH], int rows) {
int x, y;
int neighbors[HEIGHT][WIDTH];
for (y = 0; y < rows; y++)
for (x = 0; x < WIDTH; x++)
neighbors[y][x] = count_neighbors(board, rows, y, x);
for (y = 0; y < rows; y++)
for (x = 0; x < WIDTH; x++)
if (board[y][x] == 1) { /* Currently alive */
if (neighbors[y][x] < 2)
board[y][x] = 0; /* Death by boredom */
else if (neighbors[y][x] > 3)
board[y][x] = 0; /* Death by overcrowding */
}
else { /* Currently empty */
if (neighbors[y][x] == 3)
board[y][x] = 1;
}
}
steplook for something changing, and return a boolean that you can use as the condition in your loop.