Skip to content

Commit 6dd9b07

Browse files
committed
Follow-up fix: check for end-of-game when leaving edit mode.
If the user edits the board into a state where the game has ended, we suppress reporting end of game until the user leaves edit mode. At that point, check for checkmate or draw that should result in the game being terminated. The previous commit left the UI in a state where a player could be checkmated, but we would still ask them to make a move when no legal moves existed. Now we will immediately report that the game is over as soon as the user leaves edit mode.
1 parent 30b13a9 commit 6dd9b07

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/uiwin32.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bool Global_SpeakMovesFlag = true;
3131
bool Global_EnableMateAnnounce = true;
3232
extern bool Global_EnableOppTime;
3333
extern int Global_AnalysisType;
34+
extern bool Global_LeftEditMode;
3435

3536
const uintptr_t INVALID_THREAD = static_cast<uintptr_t>(-1L);
3637

@@ -953,6 +954,17 @@ bool ProcessChessCommands ( ChessBoard &board, int &source, int &dest )
953954
MessageBox ( HwndMain, msg, "File Open Error", MB_OK | MB_ICONERROR );
954955
}
955956
}
957+
else if (Global_LeftEditMode)
958+
{
959+
// The user just exited edit mode.
960+
Global_LeftEditMode = false;
961+
// We need to make a NULL move so that legal move list gets regenerated,
962+
// *and* the correct player will move,
963+
// *and* we will detect end-of-game properly.
964+
source = 0;
965+
dest = SPECIAL_MOVE_NULL;
966+
itIsTimeToCruise = true;
967+
}
956968

957969
return itIsTimeToCruise;
958970
}

src/wingui.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ bool Global_GameSaveFlag = false;
3232
bool Global_HaveFilename = false;
3333
bool Global_GameModifiedFlag = false;
3434
bool Global_TacticalBenchmarkFlag = false;
35+
bool Global_LeftEditMode = false;
3536
bool Global_GameOverFlag = true; // It's over before it begins!
3637
bool Global_UndoMoveFlag = false;
3738
bool Global_RedoMoveFlag = false;
@@ -2619,6 +2620,12 @@ LRESULT CALLBACK ChessWndProc (
26192620
int editMode = GetMenuState ( HmenuMain, ID_EDIT_EDITMODE, MF_BYCOMMAND );
26202621
editMode = (editMode ^ MF_CHECKED) & MF_CHECKED;
26212622
CheckMenuItem ( HmenuMain, ID_EDIT_EDITMODE, editMode | MF_BYCOMMAND );
2623+
2624+
// If leaving edit mode, we need to tell the human player to trigger a null move
2625+
// to force recalculating the game state: we need to know if the game ended
2626+
// and reflect the result on the board.
2627+
if (!editMode)
2628+
Global_LeftEditMode = true;
26222629
}
26232630
break;
26242631

0 commit comments

Comments
 (0)