From 5ef20063da838d81f9a9020a12bb69a01975a372 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Thu, 16 Apr 2026 22:30:17 +0300 Subject: Comment out BFS, I'm pretty sure it won't work no more --- path.c | 120 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'path.c') 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; -- cgit v1.2.3