mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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.
This commit is contained in:
4
tracks.c
4
tracks.c
@ -2429,6 +2429,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))
|
||||||
|
goto badmove;
|
||||||
if (c == 'T' || c == 'N')
|
if (c == 'T' || c == 'N')
|
||||||
ret->sflags[y*w+x] |= f;
|
ret->sflags[y*w+x] |= f;
|
||||||
else
|
else
|
||||||
@ -2438,6 +2440,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))
|
||||||
|
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);
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user