Add option to set random seed for deterministic behavior

Bump version to 1.6
This commit is contained in:
2022-01-15 14:40:21 -05:00
parent 476aa4bce6
commit 0272fd726d
10 changed files with 58 additions and 12 deletions

View File

@@ -6,7 +6,8 @@
int main(int argc, char* argv[]) {
char c;
int width = 0, height = 0;
char const *filename = NULL, *fg_color = NULL, *bg_color = NULL;
unsigned int seed = 0;
char const *filename = NULL, *fg_color = NULL, *bg_color = NULL, *seed_str = NULL;
struct poptOption options_table[] = {
{ "width", 'w', POPT_ARG_INT, &width, 0,
"Width of the maze", "BLOCKS" },
@@ -16,6 +17,8 @@ int main(int argc, char* argv[]) {
"Foreground (wall) color", "#rrggbb" },
{ "background", 'b', POPT_ARG_STRING, &bg_color, 0,
"Background color", "#rrggbb" },
{ "seed", 's', POPT_ARG_STRING, &seed_str, 0,
"Random seed", "SEED" },
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 }
};
@@ -53,7 +56,11 @@ int main(int argc, char* argv[]) {
exit(1);
}
}
mazemaker_generate_maze(width, height, &maze);
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);
mazemaker_free_maze(&maze);
mazemaker_options_free(options);