shithub: puzzles

Download patch

ref: 15f4fa851a5781cf77984a6046405ffa758e7b33
parent: 294a3ac6e703c2820ceb7b28a1a5492b61e9a531
author: Ben Harris <bjh21@bjh21.me.uk>
date: Thu Feb 2 18:09:19 EST 2023

Forbid lines off the grid in Pearl

While they couldn't be generated in normal play, execute_move() would
permit lines and marks across the edge of the grid that would then
generate assertion failures ("dsf_update_completion: Assertion
`INGRID(state, bx, by)' failed.").

I've added a check to execute_move() that after updating a square, the
square doesn't have any lines or marks that leave the grid.

This save file demonstrated the problem:

SAVEFILE:41:Simon Tatham's Portable Puzzle Collection
VERSZON :1:1
GAME    :5:Pearl
PARAMS  :5:5x6dt
CPARAMS :5:5x6dt
DESC    :6:eeeeee
NSTATES :1:2
STATEPOS:1:1
MOVE    :6:F1,4,2

--- a/pearl.c
+++ b/pearl.c
@@ -2278,6 +2278,16 @@
                 (ret->marks[y*w + x] & (char)l))
                 goto badmove;
 
+            /*
+             * Similarly, if we've ended up with a line or mark going
+             * off the board, that's not acceptable.
+             */
+            for (l = 1; l <= 8; l <<= 1)
+                if (((ret->lines[y*w + x] & (char)l) ||
+                     (ret->marks[y*w + x] & (char)l)) &&
+                    !INGRID(state, x+DX(l), y+DY(l)))
+                    goto badmove;
+
             move += n;
         } else if (strcmp(move, "H") == 0) {
             pearl_solve(ret->shared->w, ret->shared->h,