Exemplo n.º 1
0
 def move(self, piece: Piece, to_pos: (int, int)):
     if piece.get_color() != self.__player_turn:
         raise BadPlayerException('Bad player')
     if to_pos not in piece.get_possible_moves(self.__board, self.__turn):
         raise InvalidMove('Cannot move there')
     self.__board.move(piece, to_pos, self.__turn)
     self.__next_turn()
Exemplo n.º 2
0
    def get_possible_moves_for(self, piece: Piece) -> set:
        color = piece.get_color()
        king = self.__white_king if color == Piece.Color.WHITE else self.__black_king
        moves = piece.get_possible_moves(self.__board, self.__turn)

        if king.is_check(self.__board, self.__turn) and piece != king:
            moves = set(
                filter(lambda m: self.__can_move_save_king(piece, king, m),
                       moves))

        if piece != king:
            moves = set(
                filter(
                    lambda m: not king.can_move_cause_check(
                        self.__board, piece, m, self.__turn), moves))

        return moves