aboutsummaryrefslogtreecommitdiff
path: root/signpost.c
diff options
context:
space:
mode:
authorJonas Kölker <jonaskoelker@yahoo.com>2015-10-01 21:22:24 +0200
committerSimon Tatham <anakin@pobox.com>2015-10-03 17:12:20 +0100
commitbda4a963f447e3395a160e57ab9498278ad2fde2 (patch)
treebb9d1575a3e4fc2aafdf39e94742538ed1ce5d90 /signpost.c
parentd442b830e492535c9b0f1cb6b6c1d91ef2304bd2 (diff)
downloadpuzzles-bda4a963f447e3395a160e57ab9498278ad2fde2.zip
puzzles-bda4a963f447e3395a160e57ab9498278ad2fde2.tar.gz
puzzles-bda4a963f447e3395a160e57ab9498278ad2fde2.tar.bz2
puzzles-bda4a963f447e3395a160e57ab9498278ad2fde2.tar.xz
Fix an instance generation hang in Signpost.
Also expand the set of permissible parameters (add 1xN, Nx1 and 2x2).
Diffstat (limited to 'signpost.c')
-rw-r--r--signpost.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/signpost.c b/signpost.c
index f0784eb..aa2e13a 100644
--- a/signpost.c
+++ b/signpost.c
@@ -422,11 +422,12 @@ static game_params *custom_params(const config_item *cfg)
static char *validate_params(const game_params *params, int full)
{
- if (params->w < 2 || params->h < 2)
- return "Width and height must both be at least two";
- if (params->w == 2 && params->h == 2) /* leads to generation hang */
- return "Width and height cannot both be two";
-
+ if (params->w < 1) return "Width must be at least one";
+ if (params->h < 1) return "Height must be at least one";
+ if (full && params->w == 1 && params->h == 1)
+ /* The UI doesn't let us move these from unsolved to solved,
+ * so we disallow generating (but not playing) them. */
+ return "Width and height cannot both be one";
return NULL;
}
@@ -623,6 +624,7 @@ static int new_game_fill(game_state *state, random_state *rs,
state->dirs[taili] = 0;
nfilled = 2;
+ assert(state->n > 1);
while (nfilled < state->n) {
/* Try and expand _from_ headi; keep going if there's only one
@@ -638,6 +640,8 @@ static int new_game_fill(game_state *state, random_state *rs,
an = cell_adj(state, headi, aidx, adir);
} while (an == 1);
+ if (nfilled == state->n) break;
+
/* Try and expand _to_ taili; keep going if there's only one
* place to go to. */
an = cell_adj(state, taili, aidx, adir);
@@ -801,6 +805,9 @@ static char *new_game_desc(const game_params *params, random_state *rs,
char *ret;
int headi, taili;
+ /* this shouldn't happen (validate_params), but let's play it safe */
+ if (params->w == 1 && params->h == 1) return dupstr("1a");
+
generate:
blank_game_into(state);