From 843d4ca17def11671809786f2a5aebd75f230dd9 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 3 Feb 2023 20:52:05 +0000 Subject: [PATCH] Tolerate incorrect solutions in Inertia The "solve" operation in Inertia generates a proposed solution as a move string. But if such a move string is loaded from a save file it might not actually describe a solution. If that happens then it's possible to reach the end of the "solution" without winning, and doing so should probably cause a recalculation of the solution rather than an assertion failure ("execute_move: Assertion `ret->solnpos < ret->soln->len' failed."). I am a little concerned by the way that normal solve operations end up encoded in the save file, but the re-solvings caused by going off course don't, but I haven't got a good answer to that. Here's a save file that demonstrates the assertion failure: SAVEFILE:41:Simon Tatham's Portable Puzzle Collection GAME :7:Inertia PARAMS :3:8x8 CPARAMS :3:8x8 DESC :64:sbgwsmswwgggwggmmbwgwbssbwbsbwbbwsSmwbbsbbmggbmssgmgwbmmwmbmmwsw NSTATES :2:3 STATEPOS:1:1 MOVE 000:2:S0 MOVE 000:2:00 --- inertia.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inertia.c b/inertia.c index 2f352d3..b47d58e 100644 --- a/inertia.c +++ b/inertia.c @@ -1741,11 +1741,10 @@ static game_state *execute_move(const game_state *state, const char *move) if (ret->soln) { if (ret->dead || ret->gems == 0) discard_solution(ret); - else if (ret->soln->list[ret->solnpos] == dir) { + else if (ret->soln->list[ret->solnpos] == dir && + ret->solnpos+1 < ret->soln->len) ++ret->solnpos; - assert(ret->solnpos < ret->soln->len); /* or gems == 0 */ - assert(!ret->dead); /* or not a solution */ - } else { + else { const char *error = NULL; char *soln = solve_game(NULL, ret, NULL, &error); if (!error) {