Esempio n. 1
0
void update_board_state(Board *board_struct) {
	int** board = board_struct->board;
	for (int r = 0; r < board_struct->size_x; r++) {
		for (int c = 0; c < board_struct->size_y; c++) {
			// printf("-------- (%d,%d) -------- \n", r, c);
			int num_neighbor_cells = get_num_neighbors(r, c, board_struct);
			// 1. Die if fewer than 2 live neighbors.
			// 2. Die if more than 3 live neighbors.
			if (num_neighbor_cells < 2 || num_neighbor_cells > 3) {
				
				if (board[r][c] == 1) {
					board[r][c] = ALIVE_TO_DEAD;
				}
				else if (board[r][c] == 0) {
					board[r][c] = 0;
				}
			}
			// 3. Continue to Live if 2 or 3 neighbors.
			else if ((board[r][c] == 1)&&(num_neighbor_cells == 2 || num_neighbor_cells == 3)) {
				continue;	
			}
			// 4. Revive dead cell if exactly 3 neighbors
			else if (board[r][c] == 0 && num_neighbor_cells == 3) {
				board[r][c] = DEAD_TO_ALIVE;
			}

			// printf("---------------------------\n");
				
		}
	}
	update_board_state_final(board_struct);
}
Esempio n. 2
0
	bool is_empty() {
		return get_num_neighbors() == 0;
	}