diff options
-rw-r--r-- | mazerator.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/mazerator.c b/mazerator.c index 8ebc7d3..82620f0 100644 --- a/mazerator.c +++ b/mazerator.c @@ -84,12 +84,14 @@ char ***create_maze(int height, int width, char *wall) * - maze: The maze to excavate * - maze_height: The height of the maze * - maze_width: The width of the maze + * - start_x: X coordinate to start on + * - start_y Y coordinate to start on */ -void excavate_maze(char ***maze, int maze_height, int maze_width) +void excavate_maze(char ***maze, int maze_height, int maze_width, int start_x, int start_y) { struct stack *path = create_stack(maze_width * maze_height); - stack_push(path, 0); + stack_push(path, get_maze_pos(start_y, start_x)); int visited_pos_cnt = 0; while (1) @@ -171,6 +173,8 @@ const struct option options[] = { {"heigth", required_argument, NULL, 'h'}, {"wall", required_argument, NULL, 'W'}, {"seed", required_argument, NULL, 's'}, + {"start-x", required_argument, NULL, 'x'}, + {"start-y", required_argument, NULL, 'y'}, {"help", no_argument, NULL, 0}, {NULL, 0, NULL, 0}}; @@ -178,11 +182,13 @@ int main(int argc, char *argv[]) { int maze_width = 40; int maze_height = 20; + int start_x = 0; + int start_y = 0; char *wall = "█"; int seed = -1; int c; - while ((c = getopt_long(argc, argv, "w:h:W:s:", options, NULL)) != -1) + while ((c = getopt_long(argc, argv, "w:h:W:s:x:y:", options, NULL)) != -1) { switch (c) { @@ -204,6 +210,24 @@ int main(int argc, char *argv[]) maze_height = atoi(optarg); break; + case 'x': + if (!is_number(optarg) || atoi(optarg) < 1) + { + printf("Invalid option argument for -%c!\n", c); + exit(1); + } + + start_x = atoi(optarg); + break; + case 'y': + if (!is_number(optarg) || atoi(optarg) < 1) + { + printf("Invalid option argument for -%c!\n", c); + exit(1); + } + + start_y = atoi(optarg); + break; case 'W': wall = optarg; break; @@ -222,6 +246,8 @@ int main(int argc, char *argv[]) "Options:\n" " -w, --width WIDTH The width of the maze. (1-255) (Default: 40)\n" " -h, --heigth HEIGHT The heigth of the maze. (1-255) (Default: 20)\n" + " -x, --start-x X The x coordinate for the start position (Default: 0)\n" + " -y, --start-y Y The y coordinate for the start position (Default: 0)\n" " -w, --wall WALL Single character used as maze walls (Default: '█')\n" " -s, --seed SEED The randomization seed used for maze generation. (Any number)\n" " --help Displays usage information\n", @@ -247,7 +273,7 @@ int main(int argc, char *argv[]) char ***maze = create_maze(full_maze_height, full_maze_width, wall); - excavate_maze(maze, maze_height, maze_width); + excavate_maze(maze, maze_height, maze_width, start_x, start_y); print_maze(maze, full_maze_height, full_maze_width); } |