1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:37:45 +00:00

Chess: Add win/draw conditions, and display them.

This commit is contained in:
Peter Elliott 2020-08-11 14:10:39 -06:00 committed by Andreas Kling
parent e05372cee2
commit f2c1782d86
4 changed files with 159 additions and 3 deletions

View file

@ -352,3 +352,21 @@ bool Chess::apply_illegal_move(const Move& move, Colour colour)
return true;
}
Chess::Result Chess::game_result() const
{
bool are_legal_moves = false;
generate_moves([&](Move m) {
(void)m;
are_legal_moves = true;
return IterationDecision::Break;
});
if (are_legal_moves)
return Result::NotFinished;
if (in_check(turn()))
return Result::CheckMate;
return Result::StaleMate;
}