Allows drawing path to solution

This commit is contained in:
2022-01-18 20:05:30 -05:00
parent 08d49fbd26
commit f10d4061bd
6 changed files with 271 additions and 42 deletions

View File

@@ -7,7 +7,7 @@ int main(int argc, char* argv[]) {
char c;
int width = 0, height = 0;
unsigned int seed = 0;
char const *filename = NULL, *fg_color = NULL, *bg_color = NULL, *seed_str = NULL;
char const *filename = NULL, *fg_color = NULL, *bg_color = NULL, *path_color = NULL, *seed_str = NULL, *solution_fn = NULL;
struct poptOption options_table[] = {
{ "width", 'w', POPT_ARG_INT, &width, 0,
"Width of the maze", "BLOCKS" },
@@ -17,8 +17,12 @@ int main(int argc, char* argv[]) {
"Foreground (wall) color", "#rrggbb" },
{ "background", 'b', POPT_ARG_STRING, &bg_color, 0,
"Background color", "#rrggbb" },
{ "path", 'p', POPT_ARG_STRING, &path_color, 0,
"Path (solution) color", "#rrggbb" },
{ "seed", 's', POPT_ARG_STRING, &seed_str, 0,
"Random seed", "SEED" },
{ "solution", 'u', POPT_ARG_STRING, &solution_fn, 0,
"Output solution", "FILENAME" },
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 }
};
@@ -56,12 +60,27 @@ int main(int argc, char* argv[]) {
exit(1);
}
}
if (path_color != NULL) {
if (0 > mazemaker_options_set_path_color(options, path_color)) {
fprintf(stderr, "Unknown color: \"%s\"\n", path_color);
exit(1);
}
}
if (seed_str != NULL) {
seed = (unsigned int)atol(seed_str);
mazemaker_options_set_seed(options, seed);
}
mazemaker_generate_maze_opt(width, height, &maze, options);
mazemaker_maze_to_png_opt(&maze, filename, options);
if (solution_fn != NULL) {
maze_path_t solution;
if (mazemaker_solve(&maze, &solution) == 0) {
fprintf(stderr, "Error: no maze solution!\n");
} else {
mazemaker_path_to_png_opt(&solution, solution_fn, options);
mazemaker_path_free(&solution);
}
}
mazemaker_free_maze(&maze);
mazemaker_options_free(options);
poptFreeContext(ctx);