aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-02-01 20:12:29 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-02-01 20:32:26 +0000
commit2a9be2b89df3e6a07a1d90a06f8ac00a92d789e5 (patch)
tree7d4782b00254792cceeec25ebb81f8d16c69a755
parent17364455186ae61e015d0f0de3f09423f78d0727 (diff)
downloadpuzzles-2a9be2b89df3e6a07a1d90a06f8ac00a92d789e5.zip
puzzles-2a9be2b89df3e6a07a1d90a06f8ac00a92d789e5.tar.gz
puzzles-2a9be2b89df3e6a07a1d90a06f8ac00a92d789e5.tar.bz2
puzzles-2a9be2b89df3e6a07a1d90a06f8ac00a92d789e5.tar.xz
Mines: Don't check if the player has won if they've already lost
It can't happen in normal play, but if a save file had a "C" (clear around) move that set off a mine, Mines could end up hitting an assertion failure, "ncovered >= nmines". This was because it would check if the player had won by counting covered squares and mines, and of course an uncovered mine is no longer a covered square but is still a mine. Since winning after you're dead isn't possible (at least in Mines), we now skip the check entirely if the player has already died. This save file demonstrates the problem: SAVEFILE:41:Simon Tatham's Portable Puzzle Collection GAME :5:Mines PARAMS :1:7 CPARAMS :1:7 DESC :22:r31,u,0000C000d0000020 NSTATES :1:2 STATEPOS:1:1 MOVE :4:C6,2
-rw-r--r--mines.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/mines.c b/mines.c
index d40bb9f..16075aa 100644
--- a/mines.c
+++ b/mines.c
@@ -2146,6 +2146,8 @@ static int open_square(game_state *state, int x, int y)
break;
}
+ /* If the player has already lost, don't let them win as well. */
+ if (state->dead) return 0;
/*
* Finally, scan the grid and see if exactly as many squares
* are still covered as there are mines. If so, set the `won'