def get_theoretical_castling_right(self, klass): """Checks if a player could have a castling right in theory from looking just at the piece positions. :param klass: The type of castling move to check. See `Position.get_castling_right(type)` for values. :return: A boolean indicating whether the player could theoretically have that castling right. """ if klass not in Piece.castleclass: raise KeyError(klass) # TODO: Support Chess960. for square, enum in Piece.castle_squares[klass]: piece = self._pieces[Square(square)._x88] if not piece or Piece.enum(piece) != enum: return False return True
def __setitem__(self, square, piece): x88 = self.__get_key(square) # Make sure piece is valid check = Piece.enum(str(piece)) self._pieces[x88] = str(piece)
def test_enum(self): self.assertEqual(piece.W_PAWN, Piece.enum('P'))