aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c18
1 files changed, 15 insertions, 3 deletions
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;