Reputation: 718
Using the chess.js library (see this link), I can know if a chess game is finished, by using game_over() function.
But how do I know who won and who lost?
Upvotes: 1
Views: 1872
Reputation: 454
You would check
chess.in_checkmate();
first to see if the other side put this side in check on their last turn. If not and game over then it is a draw.
Upvotes: 1
Reputation: 8392
According to the docs: game_over "Returns true if the game has ended via checkmate, stalemate, draw, threefold repetition, or insufficient material". So it may have been a draw too.
I would check:
Keep in mind, though, that a chess game can also be won by the other party resigning, or running out of time on their clock.
Upvotes: 1
Reputation: 5557
in_checkmate()
Returns true or false if the side to move has been checkmated.
Combined with turn()
, it gives you the winner / loser (if it's not a draw).
Upvotes: 8