From 8ebdfdb2949af07219ea57b36352007b5f96d437 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Thu, 26 Mar 2026 14:17:23 +0300 Subject: Add options to choose the amount of directions --- main.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index e0e6ad9..79cd630 100644 --- a/main.c +++ b/main.c @@ -59,6 +59,7 @@ int main(int argc, char **argv) { char is_maze = 0; char anim = 0; + int dirs = 8; /* Handle args. * Currently supported: @@ -66,7 +67,7 @@ int main(int argc, char **argv) { * -m {width}x{height} to give a maze of given size * -f {filename} to load a map from the filename */ int opt; - while ((opt = getopt(argc, argv, ":am:f:")) != -1) { + while ((opt = getopt(argc, argv, ":am:f:48")) != -1) { switch (opt) { case 'a': anim = 1; break; case 'm': @@ -83,6 +84,8 @@ int main(int argc, char **argv) { case 'f': map = file_plaintext_map(optarg, &width, &height, &start_pos, &end_pos); break; + case '4': dirs = 4; break; + case '8': dirs = 8; break; case '?': error("Unknown option: %c\n", optopt); case ':': error("Option %c requires an argument\n", optopt); } @@ -112,7 +115,12 @@ int main(int argc, char **argv) { //print_map_out(map, width, height); char visited[height][width]; - Path path = breadth_first_search_path_8dir(map, width, height, start_pos, end_pos, visited, anim); + Path path = NULL; + if (dirs == 4) { + path = breadth_first_search_path_4dir(map, width, height, start_pos, end_pos, visited, anim); + } else { + path = breadth_first_search_path_8dir(map, width, height, start_pos, end_pos, visited, anim); + } while (1) { draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, NULL, path, visited, NULL); @@ -127,7 +135,11 @@ int main(int argc, char **argv) { map_free(map, height); map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL)); path_free(path, height); - path = breadth_first_search_path_8dir(map, width, height, start_pos, end_pos, visited, anim); + if (dirs == 4) { + path = breadth_first_search_path_4dir(map, width, height, start_pos, end_pos, visited, anim); + } else { + path = breadth_first_search_path_8dir(map, width, height, start_pos, end_pos, visited, anim); + } } break; case 'q': map_free(map, height); path_free(path, height); endwin(); return 0; -- cgit v1.2.3