aboutsummaryrefslogtreecommitdiff
path: root/pattern.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2005-02-24 09:13:06 +0000
committerSimon Tatham <anakin@pobox.com>2005-02-24 09:13:06 +0000
commitf64dcb909da33543b9b5c0f421be84c5c984f503 (patch)
tree1789beff24d577afd4e5f2fbfd0ba09a17fafd6d /pattern.c
parente500ef963734dcf35ffa146ee917e0e0e09c325c (diff)
downloadpuzzles-f64dcb909da33543b9b5c0f421be84c5c984f503.zip
puzzles-f64dcb909da33543b9b5c0f421be84c5c984f503.tar.gz
puzzles-f64dcb909da33543b9b5c0f421be84c5c984f503.tar.bz2
puzzles-f64dcb909da33543b9b5c0f421be84c5c984f503.tar.xz
Stop the Pattern grid generation from generating an entire row or
column of the same colour (at least when the dimensions are big enough to make this feasible). It's a little bit too easy otherwise! [originally from svn r5391]
Diffstat (limited to 'pattern.c')
-rw-r--r--pattern.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/pattern.c b/pattern.c
index 66ed134..4fc1562 100644
--- a/pattern.c
+++ b/pattern.c
@@ -417,6 +417,34 @@ static unsigned char *generate_soluble(random_state *rs, int w, int h)
generate(rs, w, h, grid);
+ /*
+ * The game is a bit too easy if any row or column is
+ * completely black or completely white. An exception is
+ * made for rows/columns that are under 3 squares,
+ * otherwise nothing will ever be successfully generated.
+ */
+ ok = TRUE;
+ if (w > 2) {
+ for (i = 0; i < h; i++) {
+ int colours = 0;
+ for (j = 0; j < w; j++)
+ colours |= (grid[i*w+j] == GRID_FULL ? 2 : 1);
+ if (colours != 3)
+ ok = FALSE;
+ }
+ }
+ if (h > 2) {
+ for (j = 0; j < w; j++) {
+ int colours = 0;
+ for (i = 0; i < h; i++)
+ colours |= (grid[i*w+j] == GRID_FULL ? 2 : 1);
+ if (colours != 3)
+ ok = FALSE;
+ }
+ }
+ if (!ok)
+ continue;
+
memset(matrix, 0, w*h);
do {