Tracks: tighten up the 'illegal solve submoves' fix.

Chris mentioned in the commit message that there was a risk that
illegal moves might be permitted when playing on after a solve. So
I've changed the condition so that it depends only on whether the move
_currently being executed_ is a solve, rather than whether there was a
solve action anywhere in the undo history.

(Also, wrapped overlong lines while I was here.)
This commit is contained in:
Simon Tatham
2023-01-19 12:47:55 +00:00
parent b5e02b0b9c
commit b4aaa11943

View File

@ -2408,6 +2408,7 @@ static game_state *execute_move(const game_state *state, const char *move)
int w = state->p.w, x, y, n, i; int w = state->p.w, x, y, n, i;
char c, d; char c, d;
unsigned f; unsigned f;
bool move_is_solve = false;
game_state *ret = dup_game(state); game_state *ret = dup_game(state);
/* this is breaking the bank on GTK, which vsprintf's into a fixed-size buffer /* this is breaking the bank on GTK, which vsprintf's into a fixed-size buffer
@ -2418,6 +2419,7 @@ static game_state *execute_move(const game_state *state, const char *move)
c = *move; c = *move;
if (c == 'S') { if (c == 'S') {
ret->used_solve = true; ret->used_solve = true;
move_is_solve = true;
move++; move++;
} else if (c == 'T' || c == 't' || c == 'N' || c == 'n') { } else if (c == 'T' || c == 't' || c == 'N' || c == 'n') {
/* set track, clear track; set notrack, clear notrack */ /* set track, clear track; set notrack, clear notrack */
@ -2429,7 +2431,8 @@ static game_state *execute_move(const game_state *state, const char *move)
f = (c == 'T' || c == 't') ? S_TRACK : S_NOTRACK; f = (c == 'T' || c == 't') ? S_TRACK : S_NOTRACK;
if (d == 'S') { if (d == 'S') {
if (!ui_can_flip_square(ret, x, y, f == S_NOTRACK) && !ret->used_solve) if (!ui_can_flip_square(ret, x, y, f == S_NOTRACK) &&
!move_is_solve)
goto badmove; goto badmove;
if (c == 'T' || c == 'N') if (c == 'T' || c == 'N')
ret->sflags[y*w+x] |= f; ret->sflags[y*w+x] |= f;
@ -2440,7 +2443,8 @@ static game_state *execute_move(const game_state *state, const char *move)
unsigned df = 1<<i; unsigned df = 1<<i;
if (MOVECHAR(df) == d) { if (MOVECHAR(df) == d) {
if (!ui_can_flip_edge(ret, x, y, df, f == S_NOTRACK) && !ret->used_solve) if (!ui_can_flip_edge(ret, x, y, df, f == S_NOTRACK) &&
!move_is_solve)
goto badmove; goto badmove;
if (c == 'T' || c == 'N') if (c == 'T' || c == 'N')
S_E_SET(ret, x, y, df, f); S_E_SET(ret, x, y, df, f);