isStalemate method

bool isStalemate()

Checks if the game is in a stalemate state.

Implementation

bool isStalemate() {
  for (int fromRow = 0; fromRow < 8; fromRow++) {
    for (int fromCol = 0; fromCol < 8; fromCol++) {
      ChessPiece? piece = getPiece(Position(row: fromRow, col: fromCol));
      if (piece == null || piece.color != turn) continue;
      for (int toRow = 0; toRow < 8; toRow++) {
        for (int toCol = 0; toCol < 8; toCol++) {
          if (MoveValidator.isValidMove(
            this,
            Position(row: fromRow, col: fromCol),
            Position(row: toRow, col: toCol),
          )) {
            return false;
          }
        }
      }
    }
  }
  return !isKingInCheck();
}