shithub: puzzles

Download patch

ref: 47de8f449c2a70a6db897e583396afd080bb6157
parent: f018ef97d34b9126744e63cc2112c302fcae4ab4
author: Simon Tatham <[email protected]>
date: Sat Mar 11 17:13:52 EST 2023

Galaxies: remove the 'maxtries' system.

Most games in this collection don't have one. If you ask them for a
hard puzzle, they'll just keep looping round until they actually
manage to deliver one. We try to arrange that the standard presets
don't take too long to generate, but if the user turns up the game
size _and_ uses an expensive difficulty level, our view is that that's
up to them.

After fixing the bug from the previous commit in which the Galaxies
recursion depth limit was not actually doing anything, even 15x15
Unreasonable now generates happily in under a second. So I don't see
any reason why Galaxies should be an exception.

Hence, now if you ask Galaxies for an Unreasonable puzzle, you _will_
get a puzzle that it grades as Unreasonable, even if that takes a long
time to generate.

--- a/galaxies.c
+++ b/galaxies.c
@@ -1316,10 +1316,7 @@
 }
 
 #ifdef STANDALONE_SOLVER
-static int maxtries;
-#define MAXTRIES maxtries
-#else
-#define MAXTRIES 50
+static bool one_try; /* override for soak testing */
 #endif
 
 #define GP_DOTS   1
@@ -1390,7 +1387,7 @@
     game_state *state = blank_game(params->w, params->h), *copy;
     char *desc;
     int *scratch, sz = state->sx*state->sy, i;
-    int diff, ntries = 0;
+    int diff;
     bool cc;
 
     /* Random list of squares to try and process, one-by-one. */
@@ -1399,7 +1396,6 @@
 
 generate:
     clear_game(state, true);
-    ntries++;
 
     /* generate_pass(state, rs, scratch, 10, GP_DOTS); */
     /* generate_pass(state, rs, scratch, 100, 0); */
@@ -1432,12 +1428,17 @@
     assert(diff != DIFF_IMPOSSIBLE);
     if (diff != params->diff) {
         /*
-         * We'll grudgingly accept a too-easy puzzle, but we must
-         * _not_ permit a too-hard one (one which the solver
-         * couldn't handle at all).
+         * If the puzzle was insoluble at this difficulty level (i.e.
+         * too hard), _or_ soluble at a lower level (too easy), go
+         * round again.
+         *
+         * An exception is in soak-testing mode, where we return the
+         * first puzzle we got regardless.
          */
-        if (diff > params->diff ||
-            ntries < MAXTRIES) goto generate;
+#ifdef STANDALONE_SOLVER
+        if (!one_try)
+#endif
+            goto generate;
     }
 
 #ifdef STANDALONE_PICTURE_GENERATOR
@@ -4146,7 +4147,7 @@
 #endif
     tt_start = tt_now = time(NULL);
     for (i = 0; i < DIFF_MAX; i++) diffs[i] = 0;
-    maxtries = 1;
+    one_try = true;
 
     printf("Soak-generating a %dx%d grid, max. diff %s.\n",
            p->w, p->h, galaxies_diffnames[p->diff]);
@@ -4211,8 +4212,6 @@
             id = p;
         }
     }
-
-    maxtries = 50;
 
     p = default_params();
     rs = random_new((void*)&seed, sizeof(time_t));