checkForGameEnd method
one time spectation
Implementation
GameOverBy? checkForGameEnd(ChessBoardInterface game) {
GameOverBy? gameOverBy;
if (game.isCheckmate()) {
gameOverBy = GameOverBy.checkmate;
} else if (game.isStalemate()) {
gameOverBy = GameOverBy.stalemate;
} else if (game.isDraw) {
gameOverBy = GameOverBy.draw;
} else if (game.resign != null) {
gameOverBy = GameOverBy.resign;
} else if (game.isTimeOut()) {
gameOverBy = GameOverBy.timeout;
} else if (game.isInsufficientMaterial()) {
gameOverBy = GameOverBy.insufficientMaterial;
} else if (game.isThreefoldRepetition()) {
gameOverBy = GameOverBy.threefoldRepetition;
} else if (game.isFiftyMoveDraw()) {
gameOverBy = GameOverBy.fiftyMoveRule;
}
if (gameOverBy != null && onGameOver != null) {
onGameOver!(gameOverBy);
}
return gameOverBy;
}