From 0bd1a8057841386754f9f4a8a268616c7ce80e80 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 1 Apr 2023 18:54:29 +0100 Subject: [PATCH] Magnets: add a check that magnets don't wrap between lines There was nothing in Magnet's description validation to prevent there being the left end of a magnet at the right end of a row and the right end of a magnet at the left end of the row below. Indeed as far as I can such a game (e.g. 3x3:..2,2..,...,1.1,TLRB*LRLR) plays entirely correctly except that one magnet is discontinuous. While this worked, it was entirely an artefact of the particular memory layout that Magnets uses and shouldn't have been allowed, so I've added an additional validation rule to stop it. --- magnets.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/magnets.c b/magnets.c index d95d146..0669978 100644 --- a/magnets.c +++ b/magnets.c @@ -521,6 +521,8 @@ nextchar: for (idx = 0; idx < state->wh; idx++) { if (state->common->dominoes[idx] < 0 || state->common->dominoes[idx] >= state->wh || + (state->common->dominoes[idx] % state->w != idx % state->w && + state->common->dominoes[idx] / state->w != idx / state->w) || state->common->dominoes[state->common->dominoes[idx]] != idx) { *prob = "Domino descriptions inconsistent"; goto done;