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:
parent
e05372cee2
commit
f2c1782d86
4 changed files with 159 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue