aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2013-04-12 16:28:53 +0000
committerSimon Tatham <anakin@pobox.com>2013-04-12 16:28:53 +0000
commitc94afe9cd6ff0ad719798d7fd6fb842a336f66ed (patch)
treee8b8ed09b69fe29a5f03bb871b8a736115d0600e
parentfe6da52b26f14e539183d5eb71e2132a8bf9fa8f (diff)
downloadpuzzles-c94afe9cd6ff0ad719798d7fd6fb842a336f66ed.zip
puzzles-c94afe9cd6ff0ad719798d7fd6fb842a336f66ed.tar.gz
puzzles-c94afe9cd6ff0ad719798d7fd6fb842a336f66ed.tar.bz2
puzzles-c94afe9cd6ff0ad719798d7fd6fb842a336f66ed.tar.xz
Adjust Keen's grid generation to constrain the maximum size of clue
blocks, because 'make test' showed up very large blocks as an occasional slowdown factor in game generation (takes too long to iterate over all possibilities). This is a good idea in any case, because really big multiplicative clue numbers have trouble fitting in the square. [originally from svn r9827]
-rw-r--r--keen.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/keen.c b/keen.c
index 5087465..e951dba 100644
--- a/keen.c
+++ b/keen.c
@@ -42,6 +42,14 @@ static char const keen_diffchars[] = DIFFLIST(ENCODE);
#define CMASK 0x60000000L
#define CUNIT 0x20000000L
+/*
+ * Maximum size of any clue block. Very large ones are annoying in UI
+ * terms (if they're multiplicative you end up with too many digits to
+ * fit in the square) and also in solver terms (too many possibilities
+ * to iterate over).
+ */
+#define MAXBLK 6
+
enum {
COL_BACKGROUND,
COL_GRID,
@@ -847,26 +855,34 @@ done
x = i % w;
y = i / w;
- if (x > 0 &&
+ if (x > 0 && dsf_size(dsf, i-1) < MAXBLK &&
(best == -1 || revorder[i-1] < revorder[best]))
best = i-1;
- if (x+1 < w &&
+ if (x+1 < w && dsf_size(dsf, i+1) < MAXBLK &&
(best == -1 || revorder[i+1] < revorder[best]))
best = i+1;
- if (y > 0 &&
+ if (y > 0 && dsf_size(dsf, i-w) < MAXBLK &&
(best == -1 || revorder[i-w] < revorder[best]))
best = i-w;
- if (y+1 < w &&
+ if (y+1 < w && dsf_size(dsf, i+w) < MAXBLK &&
(best == -1 || revorder[i+w] < revorder[best]))
best = i+w;
if (best >= 0) {
- singletons[i] = FALSE;
+ singletons[i] = singletons[best] = FALSE;
dsf_merge(dsf, i, best);
}
}
}
+ /* Quit and start again if we have any singletons left over
+ * which we weren't able to do anything at all with. */
+ for (i = 0; i < a; i++)
+ if (singletons[i])
+ break;
+ if (i < a)
+ continue;
+
/*
* Decide what would be acceptable clues for each block.
*