aboutsummaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2005-04-29 17:07:19 +0000
committerSimon Tatham <anakin@pobox.com>2005-04-29 17:07:19 +0000
commit79a77d53e1723f06527486dd4f36857e89944eaa (patch)
tree782962d39f693c25566adf88339595cd3e131882 /gtk.c
parentd55d0b53f3f14e34246987af38263ba88470875a (diff)
downloadpuzzles-79a77d53e1723f06527486dd4f36857e89944eaa.zip
puzzles-79a77d53e1723f06527486dd4f36857e89944eaa.tar.gz
puzzles-79a77d53e1723f06527486dd4f36857e89944eaa.tar.bz2
puzzles-79a77d53e1723f06527486dd4f36857e89944eaa.tar.xz
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]
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c68
1 files changed, 62 insertions, 6 deletions
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:
+ *
+ * <puzzle-name> --generate [<n> [<params>]]
+ *
+ * <n>, if present, is the number of puzzle IDs to generate.
+ * <params>, 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 <params>, you must also specify <n> (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;
}