From bf9abb2a127a4a81babe50ecb419527f8aeffe28 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 10 Feb 2023 17:09:18 +0000 Subject: Forbid impossible moves in Bridges Specifically, a bridge or a non-bridge must connect two islands that differ in precisely one co-ordinate. Without this, a save file that tries to connect or disconnect two non-orthogonal islands will cause "island_join: Assertion `!"island_join: islands not orthogonal."' failed." Here's a save file demonstrating the problem: SAVEFILE:41:Simon Tatham's Portable Puzzle Collection VERSION :1:1 GAME :7:Bridges PARAMS :13:3x3i30e10m2d0 CPARAMS :13:3x3i30e10m2d0 DESC :6:b1c1a2 NSTATES :1:2 STATEPOS:1:2 MOVE :10:L0,2,2,0,1 --- bridges.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bridges.c') diff --git a/bridges.c b/bridges.c index db4a66e..3226334 100644 --- a/bridges.c +++ b/bridges.c @@ -2571,6 +2571,8 @@ static game_state *execute_move(const game_state *state, const char *move) goto badmove; if (!INGRID(ret, x1, y1) || !INGRID(ret, x2, y2)) goto badmove; + /* Precisely one co-ordinate must differ between islands. */ + if ((x1 != x2) + (y1 != y2) != 1) goto badmove; is1 = INDEX(ret, gridi, x1, y1); is2 = INDEX(ret, gridi, x2, y2); if (!is1 || !is2) goto badmove; @@ -2582,6 +2584,7 @@ static game_state *execute_move(const game_state *state, const char *move) goto badmove; if (!INGRID(ret, x1, y1) || !INGRID(ret, x2, y2)) goto badmove; + if ((x1 != x2) + (y1 != y2) != 1) goto badmove; is1 = INDEX(ret, gridi, x1, y1); is2 = INDEX(ret, gridi, x2, y2); if (!is1 || !is2) goto badmove; -- cgit v1.1