From f2a99859f0c66ba17765c036a173e7f29927327a Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Thu, 16 Apr 2026 22:15:51 +0300 Subject: Fix costs --- main.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 93ce49f..b216c3b 100644 --- a/main.c +++ b/main.c @@ -141,7 +141,7 @@ int main(int argc, char **argv) { char **visited = visited_new(width, height); Path path = NULL; - path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim); + path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); if (bmp_only) { map_to_bmp(map, width, height, start_pos, end_pos, path, visited, bmp_filename); @@ -191,7 +191,7 @@ int main(int argc, char **argv) { else anim = 1; path_free(path, height); - path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim); + path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); clear_message(); break; @@ -199,7 +199,7 @@ int main(int argc, char **argv) { if (path_func == astar_path) { set_message("Dijkstra"); path_func = &dijkstra_path; } else { set_message("A*"); path_func = &astar_path; }; path_free(path, height); - path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim); + path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); break; case 'y': @@ -216,6 +216,8 @@ int main(int argc, char **argv) { map_free(map, height); visited_free(visited, height); path_free(path, height); + cost_free(cell_costs, height); + cell_costs = NULL; height = mheight * 2 - 1; width = mwidth * 2 - 1; @@ -224,7 +226,7 @@ int main(int argc, char **argv) { map = rbt_maze_map(mwidth, mheight, rand()); visited = visited_new(width, height); - path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim); + path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); } break; @@ -256,11 +258,13 @@ int main(int argc, char **argv) { map_free(map, height); path_free(path, height); + cost_free(cell_costs, height); + cell_costs = NULL; visited = visited_new(width, height); map = file_plaintext_map(filename, &width, &height, &start_pos, &end_pos); visited = visited_new(width, height); - path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim); + path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); set_message("Loaded map from %s", filename); print_message(height); @@ -272,9 +276,11 @@ int main(int argc, char **argv) { case 'n': if (is_maze) { map_free(map, height); - map = rbt_maze_map(mwidth, mheight, rand()); path_free(path, height); - path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim); + cost_free(cell_costs, height); + cell_costs = NULL; + map = rbt_maze_map(mwidth, mheight, rand()); + path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); } break; @@ -286,33 +292,33 @@ int main(int argc, char **argv) { print_message(height); char cost_filename[FILENAME_BUF_SIZE] = "\0"; mvgetnstr(height + map_offset_y + 1, map_offset_x - 2 + sizeof(FILENAME_PROMPT), cost_filename, FILENAME_BUF_SIZE - 1); + curs_set(0); /* Hide the cursor */ + noecho(); /* Don't echo characters */ cell_costs = file_plaintext_costs(cost_filename, width, height); path_free(path, height); path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); - /* TODO: figure out how to print actual costs */ - cost_free(cell_costs, height); - curs_set(0); /* Hide the cursor */ - noecho(); /* Don't echo characters */ break; case 'e': is_maze = 0; visited_free(visited, height); path_free(path, height); + cost_free(cell_costs, height); + cell_costs = NULL; map_editor(&map, &width, &height, &start_pos, &end_pos, dirs); set_message("You've left the map editor"); print_message(height); wrefresh(curscr); visited = visited_new(width, height); - path = path_func(dirs, map, NULL, width, height, start_pos, end_pos, visited, anim); + path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); break; case KEY_RESIZE: clear(); break; - case 'q': map_free(map, height); path_free(path, height); endwin(); return 0; + case 'q': cost_free(cell_costs, height); visited_free(visited, height); map_free(map, height); path_free(path, height); endwin(); return 0; } } -- cgit v1.2.3