From b0b6aecd5cb3a9a02376ec071699f827feee6934 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Sun, 22 Mar 2026 11:25:36 +0300 Subject: Add rendering of visited tiles --- path.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'path.c') 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); -- cgit v1.2.3