shithub: puzzles

Download patch

ref: 5782e29db43034574763b1d10c48486c3e95f0d2
parent: 15974d06bbaad287382c6eeb8deb7c6f3a627278
author: Ben Harris <bjh21@bjh21.me.uk>
date: Mon Jan 9 15:24:15 EST 2023

Tracks: make sure moves are valid in execute_move()

Tracks allowed moves in execute_move() that shouldn't have been allowed,
like changing the state of the edges of the board.  This moves couldn't
be generated by interpret_move(), but could be loaded from a save file.
Now execute_move() uses the same ui_can_flip_*() functions as
interpret_move() to decide whether a particular move is allowed.  This
should prevent some assertion failures when loading corrupted save
files.

--- a/tracks.c
+++ b/tracks.c
@@ -2429,6 +2429,8 @@
             f = (c == 'T' || c == 't') ? S_TRACK : S_NOTRACK;
 
             if (d == 'S') {
+                if (!ui_can_flip_square(ret, x, y, f == S_NOTRACK))
+                    goto badmove;
                 if (c == 'T' || c == 'N')
                     ret->sflags[y*w+x] |= f;
                 else
@@ -2438,6 +2440,8 @@
                     unsigned df = 1<<i;
 
                     if (MOVECHAR(df) == d) {
+                        if (!ui_can_flip_edge(ret, x, y, df, f == S_NOTRACK))
+                            goto badmove;
                         if (c == 'T' || c == 'N')
                             S_E_SET(ret, x, y, df, f);
                         else