aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-02-02 22:26:24 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-02-02 22:26:47 +0000
commit294a3ac6e703c2820ceb7b28a1a5492b61e9a531 (patch)
treee4be972d5130bc928d111ce046ed36a49b9b2455
parented682bd5c608156d12ebaa2d84c4ce2e2877c10a (diff)
downloadpuzzles-294a3ac6e703c2820ceb7b28a1a5492b61e9a531.zip
puzzles-294a3ac6e703c2820ceb7b28a1a5492b61e9a531.tar.gz
puzzles-294a3ac6e703c2820ceb7b28a1a5492b61e9a531.tar.bz2
puzzles-294a3ac6e703c2820ceb7b28a1a5492b61e9a531.tar.xz
Dominosa: require the two halves of a domino to be adjacent
Also that a line indicating no domino be between adjacent squares. Without this, execute_move would allow you to place dominos and edges between any pair ot squares, and then generate assertion failures ("execute_move: Assertion `d2 - w >= 0' failed." and "execute_move: Assertion `d1 - w >= 0' failed.") when a domino was placed over an invalid edge. This example save file demonstrates the problem: SAVEFILE:41:Simon Tatham's Portable Puzzle Collection GAME :8:Dominosa PARAMS :1:6 CPARAMS :1:6 DESC :56:55521461210004364611033535444421636022603153156422620503 NSTATES :1:3 STATEPOS:1:3 MOVE :4:E0,2 MOVE :4:D0,2
-rw-r--r--dominosa.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/dominosa.c b/dominosa.c
index e60cb46..61b345e 100644
--- a/dominosa.c
+++ b/dominosa.c
@@ -2896,7 +2896,8 @@ static game_state *execute_move(const game_state *state, const char *move)
move++;
} else if (move[0] == 'D' &&
sscanf(move+1, "%d,%d%n", &d1, &d2, &p) == 2 &&
- d1 >= 0 && d1 < wh && d2 >= 0 && d2 < wh && d1 < d2) {
+ d1 >= 0 && d1 < wh && d2 >= 0 && d2 < wh && d1 < d2 &&
+ (d2 - d1 == 1 || d2 - d1 == w)) {
/*
* Toggle domino presence between d1 and d2.
@@ -2964,7 +2965,8 @@ static game_state *execute_move(const game_state *state, const char *move)
} else if (move[0] == 'E' &&
sscanf(move+1, "%d,%d%n", &d1, &d2, &p) == 2 &&
d1 >= 0 && d1 < wh && d2 >= 0 && d2 < wh && d1 < d2 &&
- ret->grid[d1] == d1 && ret->grid[d2] == d2) {
+ ret->grid[d1] == d1 && ret->grid[d2] == d2 &&
+ (d2 - d1 == 1 || d2 - d1 == w)) {
/*
* Toggle edge presence between d1 and d2.