aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Lyles <kevinlyles@gmail.com>2015-05-16 13:51:34 -0500
committerSimon Tatham <anakin@pobox.com>2015-05-22 08:18:33 +0100
commita614347a3e5fe106e69fd697fb08d50cda81f83b (patch)
treea2c08fea12518662fa3734339ab988d0b063a0d2
parent80c1a6932939be245ed8f88cf34dc7487b6788f0 (diff)
downloadpuzzles-a614347a3e5fe106e69fd697fb08d50cda81f83b.zip
puzzles-a614347a3e5fe106e69fd697fb08d50cda81f83b.tar.gz
puzzles-a614347a3e5fe106e69fd697fb08d50cda81f83b.tar.bz2
puzzles-a614347a3e5fe106e69fd697fb08d50cda81f83b.tar.xz
Cleaned up execute_move a little
-rw-r--r--towers.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/towers.c b/towers.c
index 011a406..2b9e4e7 100644
--- a/towers.c
+++ b/towers.c
@@ -1391,35 +1391,29 @@ static char *interpret_move(const game_state *state, game_ui *ui,
static game_state *execute_move(const game_state *from, const char *move)
{
int w = from->par.w, a = w*w;
- game_state *ret;
+ game_state *ret = dup_game(from);
int x, y, i, n;
if (move[0] == 'S') {
- ret = dup_game(from);
ret->completed = ret->cheated = TRUE;
for (i = 0; i < a; i++) {
- if (move[i+1] < '1' || move[i+1] > '0'+w) {
- free_game(ret);
- return NULL;
- }
+ if (move[i+1] < '1' || move[i+1] > '0'+w)
+ goto badmove;
ret->grid[i] = move[i+1] - '0';
ret->pencil[i] = 0;
}
- if (move[a+1] != '\0') {
- free_game(ret);
- return NULL;
- }
+ if (move[a+1] != '\0')
+ goto badmove;
return ret;
} else if ((move[0] == 'P' || move[0] == 'R') &&
sscanf(move+1, "%d,%d,%d", &x, &y, &n) == 3 &&
x >= 0 && x < w && y >= 0 && y < w && n >= 0 && n <= w) {
if (from->clues->immutable[y*w+x])
- return NULL;
+ goto badmove;
- ret = dup_game(from);
if (move[0] == 'P' && n > 0) {
ret->pencil[y*w+x] ^= 1L << n;
} else {
@@ -1437,14 +1431,17 @@ static game_state *execute_move(const game_state *from, const char *move)
* starting point when following through a set of
* diagnostics output by the standalone solver.)
*/
- ret = dup_game(from);
for (i = 0; i < a; i++) {
if (!ret->grid[i])
ret->pencil[i] = (1L << (w+1)) - (1L << 1);
}
return ret;
- } else
- return NULL; /* couldn't parse move string */
+ }
+
+ badmove:
+ /* couldn't parse move string */
+ free_game(ret);
+ return NULL;
}
/* ----------------------------------------------------------------------