aboutsummaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'path.c')
-rw-r--r--path.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/path.c b/path.c
index 19fdf0b..346f737 100644
--- a/path.c
+++ b/path.c
@@ -8,8 +8,7 @@
#include "priority_queue.h"
/* BLOODY FUCK IT WORKS */
-Path breadth_first_search_path_4dir(Map map, size_t width, size_t height, Position start, Position end) {
- (void) map, (void)end;
+Path breadth_first_search_path_4dir(Map map, size_t width, size_t height, Position start, Position end, char visited[height][width]) {
Path path = malloc(sizeof(PathNode)*height);
if (path == NULL) return NULL;
@@ -20,13 +19,17 @@ Path breadth_first_search_path_4dir(Map map, size_t width, size_t height, Positi
}
PositionPQ *frontier = ppq_new(start, 0);
- char visited[height][width];
+
memset(visited, 0, height * width * sizeof(char));
while (frontier != NULL) {
Position cur = ppq_pop(&frontier);
visited[cur.y][cur.x] = 1;
+ if (cur.x == end.x && cur.y == end.y) {
+ break;
+ }
+
Position na[4];
unsigned int nc = neighbours(na, cur, width, height, visited);