From 79a77d53e1723f06527486dd4f36857e89944eaa Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 29 Apr 2005 17:07:19 +0000 Subject: Added a `--generate' command-line option in the GTK port of every puzzle, to make it construcct puzzle IDs and output them on stdout. Also checked in print.py, a script which reads puzzle IDs on stdin and produces PostScript output. With these, you can generate pages of Pattern, Rectangles and Solo puzzles to take on trains with you. [originally from svn r5707] --- gtk.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 6 deletions(-) (limited to 'gtk.c') diff --git a/gtk.c b/gtk.c index 5690eae..93a81d2 100644 --- a/gtk.c +++ b/gtk.c @@ -1031,14 +1031,70 @@ int main(int argc, char **argv) char *pname = argv[0]; char *error; - gtk_init(&argc, &argv); + /* + * Special standalone mode for generating puzzle IDs on the + * command line. Useful for generating puzzles to be printed + * out and solved offline (for puzzles where that even makes + * sense - Solo, for example, is a lot more pencil-and-paper + * friendly than Net!) + * + * Usage: + * + * --generate [ []] + * + * , if present, is the number of puzzle IDs to generate. + * , if present, is the same type of parameter string + * you would pass to the puzzle when running it in GUI mode, + * including optional extras such as the expansion factor in + * Rectangles and the difficulty level in Solo. + * + * If you specify , you must also specify (although + * you may specify it to be 1). Sorry; that was the + * simplest-to-parse command-line syntax I came up with. + */ + if (argc > 1 && !strcmp(argv[1], "--generate")) { + int n = 1; + char *params = NULL; + game_params *par; + random_state *rs; + char *parstr; + + { + void *seed; + int seedlen; + get_random_seed(&seed, &seedlen); + rs = random_init(seed, seedlen); + } - if (!new_window(argc > 1 ? argv[1] : NULL, &error)) { - fprintf(stderr, "%s: %s\n", pname, error); - return 1; - } + if (argc > 2) + n = atoi(argv[2]); + if (argc > 3) + params = argv[3]; + + if (params) + par = thegame.decode_params(params); + else + par = thegame.default_params(); + parstr = thegame.encode_params(par); + + while (n-- > 0) { + char *seed = thegame.new_seed(par, rs); + printf("%s:%s\n", parstr, seed); + sfree(seed); + } - gtk_main(); + return 0; + } else { + + gtk_init(&argc, &argv); + + if (!new_window(argc > 1 ? argv[1] : NULL, &error)) { + fprintf(stderr, "%s: %s\n", pname, error); + return 1; + } + + gtk_main(); + } return 0; } -- cgit v1.1