chiark / gitweb /
Format Palisade solve-type moves in sensible ASCII.
authorSimon Tatham <anakin@pobox.com>
Tue, 3 Nov 2015 06:56:47 +0000 (06:56 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 3 Nov 2015 06:59:47 +0000 (06:59 +0000)
The solve move stored in 'aux' by new_game_desc consists of printable
characters in the range '@' to 'O', each representing a 4-bit bitmap
of edges around a cell. But the one generated on the fly by
solve_game() was missing out the 0x40 bit and just returning
characters in the range ^@ to ^O - which would not only have been
horrible if you found such a string in a save file, but also meant
that a game with any completely borderless square would have a
solution move string terminating early due to the ^@, causing
execute_move() to reject it.

Example: ./palisade --test-solve --generate 1 5x5n5#12345-37 now
succeeds, where previously it failed an assertion.

palisade.c

index 8776cc15c18119a44f8dbb9d2ca5712bc492ec93..f7b379128505d5fa0a6d5c01efa391e4d1b226f6 100644 (file)
@@ -755,8 +755,12 @@ static char *solve_game(const game_state *state, const game_state *currstate,
     init_borders(w, h, move + 1);
     move[wh + 1] = '\0';
 
-    if (solver(&state->shared->params, state->shared->clues, move + 1))
+    if (solver(&state->shared->params, state->shared->clues, move + 1)) {
+        int i;
+        for (i = 0; i < wh; i++)
+            move[i+1] |= '@';          /* turn into sensible ASCII */
         return (char *) move;
+    }
 
     *error = "Sorry, I can't solve this puzzle";
     sfree(move);