diff options
| -rw-r--r-- | path.c | 120 | ||||
| -rw-r--r-- | path.h | 2 |
2 files changed, 61 insertions, 61 deletions
@@ -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; @@ -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); |
