Skip to content

Instantly share code, notes, and snippets.

@kvisle
Created October 20, 2010 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvisle/636977 to your computer and use it in GitHub Desktop.
Save kvisle/636977 to your computer and use it in GitHub Desktop.
int pPathfind(struct game *g, int checkonly)
{
int i = 0, x, y;
struct queue_t *queue;
struct grid_t *grid;
grid = copy_grid(g);
queue = alloc_queue(grid);
for(i=0; i < grid->size; i++) {
if (grid->ar[i] == 255) {
push(queue, grid, i, 1);
}
}
while (likely(grid->marked[HEAD(queue).id] != 0)) {
checkfield(queue, grid);
queue->head++;
}
if ( checkonly )
{
puts("We need to check if any of the entrances are blocked.");
free_queue(queue);
free_grid(grid);
}
i = 0;
for(y=0; y < G_HEIGHT; y++) {
for(x=0; x < G_WIDTH; x++) {
g->path[y][x] = grid->path[i];
i++;
}
}
free_queue(queue);
free_grid(grid);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment