#include #include #include #include "array.h" /* * Implements a linear search. */ int gol_is_live(struct gol_board *const state, int_least32_t x, int_least32_t y) { for (unsigned int i = 0; i < state->n; i += 2) { if (state->live_cells[i] == x && state->live_cells[i+1] == y) { return 1; } } return 0; } int gol_vivify(struct gol_board *const state, int_least32_t x, int_least32_t y) { int_least32_t *tmp_cells = NULL; size_t tmp_size = 0; if (state->n == state->size) { tmp_size = 2 * state->size; tmp_cells = malloc(tmp_size * sizeof(typeof(tmp_cells))); if (!tmp_cells) { return 1; } memcpy(tmp_cells, state->live_cells, tmp_size * sizeof(typeof(tmp_cells))); state->size = tmp_size; free(state->live_cells); state->live_cells = tmp_cells; } state->live_cells[state->n] = x; state->live_cells[state->n + 1] = y; state->n += 2; return 1; }