aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-16 22:30:17 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-16 22:30:17 +0300
commit5ef20063da838d81f9a9020a12bb69a01975a372 (patch)
treefbc9dea218ed96fa05b9be5fcdca9f8d68faeeb9
parent8b1cfbc49ca89916ddeaad05c346a27b3b38e6f7 (diff)
downloadastar-5ef20063da838d81f9a9020a12bb69a01975a372.tar.xz
Comment out BFS, I'm pretty sure it won't work no more
-rw-r--r--path.c120
-rw-r--r--path.h2
2 files changed, 61 insertions, 61 deletions
diff --git a/path.c b/path.c
index 6909adc..4b791c2 100644
--- a/path.c
+++ b/path.c
@@ -61,66 +61,67 @@ int anim(Map map, size_t width, size_t height, Position start, Position end, Pos
}
return 0;
}
-/* BLOODY FUCK IT WORKS */
-Path breadth_first_search_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) {
- (void)cell_costs; /* BFS doesn't support costs */
- anim_automatic = 0;
-
- /* The function to use to find neighbours */
- unsigned int (*neighbours)(Position[], size_t[], Position, size_t, size_t, char**, size_t**) = NULL;
- switch (dirs) {
- case 4: neighbours = &neighbours_4dir; break;
- case 8: neighbours = &neighbours_8dir; break;
- default: error("Tried to call breadth_first_search_path with wrong direction amount\n");
- }
-
- Path path = path_new(width, height);
- if (path == NULL) error("Path was NULL\n");
-
- PositionPQ *frontier = ppq_new(start, 0);
-
- visited_clear(visited, width, height);
-
- while (frontier != NULL) {
- Position cur = ppq_pop(&frontier);
- visited[cur.y][cur.x] = 1;
-
- if (cur.x == end.x && cur.y == end.y) {
- ppq_free(frontier);
- if (should_anim) {
- clear();
- }
- return path; /* Found path */
- }
-
- Position na[dirs];
- unsigned int nc = neighbours(na, NULL, cur, width, height, visited, NULL);
-
- for (unsigned int i = 0; i < nc; i++) {
- /* The Russian constitution doesn't allow walking on walls */
- if (map[na[i].y][na[i].x] == WALL) continue;
-
- if (ppq_insert(&frontier, na[i], 0) != PPQ_INSERT_ALREADY) {
- path[na[i].y][na[i].x] = cur;
- }
- }
-
- if (should_anim) {
- if (anim(map, width, height, start, end, &cur, visited, frontier) == -1) {
- clear();
- path_free(path, height);
- return NULL;
- }
- }
- }
- if (should_anim) {
- clear();
- }
-
- path_free(path, height);
- return NULL;
-}
+/* BLOODY FUCK IT WORKS */
+//Path breadth_first_search_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) {
+// (void)cell_costs; /* BFS doesn't support costs */
+// anim_automatic = 0;
+//
+// /* The function to use to find neighbours */
+// unsigned int (*neighbours)(Position[], size_t[], Position, size_t, size_t, char**, size_t**) = NULL;
+// switch (dirs) {
+// case 4: neighbours = &neighbours_4dir; break;
+// case 8: neighbours = &neighbours_8dir; break;
+// default: error("Tried to call breadth_first_search_path with wrong direction amount\n");
+// }
+//
+// Path path = path_new(width, height);
+// if (path == NULL) error("Path was NULL\n");
+//
+// PositionPQ *frontier = ppq_new(start, 0);
+//
+// visited_clear(visited, width, height);
+//
+// while (frontier != NULL) {
+// Position cur = ppq_pop(&frontier);
+// visited[cur.y][cur.x] = 1;
+//
+// if (cur.x == end.x && cur.y == end.y) {
+// ppq_free(frontier);
+// if (should_anim) {
+// clear();
+// }
+// return path; /* Found path */
+// }
+//
+// Position na[dirs];
+// unsigned int nc = neighbours(na, NULL, cur, width, height, visited, NULL);
+//
+// for (unsigned int i = 0; i < nc; i++) {
+// /* The Russian constitution doesn't allow walking on walls */
+// if (map[na[i].y][na[i].x] == WALL) continue;
+//
+// if (ppq_insert(&frontier, na[i], 0) != PPQ_INSERT_ALREADY) {
+// path[na[i].y][na[i].x] = cur;
+// }
+// }
+//
+// if (should_anim) {
+// if (anim(map, width, height, start, end, &cur, visited, frontier) == -1) {
+// clear();
+// path_free(path, height);
+// return NULL;
+// }
+// }
+// }
+//
+// if (should_anim) {
+// clear();
+// }
+//
+// path_free(path, height);
+// return NULL;
+//}
Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) {
anim_automatic = 0;
@@ -228,7 +229,6 @@ Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t hei
/* The Russian constitution doesn't allow walking on walls */
if (map[na[i].y][na[i].x] == WALL) continue;
- /* Dijkstra's works with cell_costs, why does this not? */
size_t new_cost = cost_so_far[cur.y][cur.x] + costs[i];
if (new_cost < cost_so_far[na[i].y][na[i].x]) {
cost_so_far[na[i].y][na[i].x] = new_cost;
diff --git a/path.h b/path.h
index 3bf4af4..bceed05 100644
--- a/path.h
+++ b/path.h
@@ -8,7 +8,7 @@
extern Path (*path_func)(int, Map, size_t **, size_t, size_t, Position, Position, char **, char);
/* dirs can be 4 or 8 to disallow or allow diagonal movement */
-Path breadth_first_search_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim);
+//Path breadth_first_search_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim);
Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim);
Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim);