Created
October 20, 2010 18:10
-
-
Save kvisle/636977 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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