Esempio n. 1
0
 def capture(self, piece: Piece, captured_position: (int, int)):
     if piece.get_color() != self.__player_turn:
         raise BadPlayerException('Bad player')
     captured = self.__get_piece_at(captured_position)
     if captured not in piece.get_possible_captures(
             self.__board,
             self.__turn) or captured.get_color() == piece.get_color():
         raise InvalidMove('Cannot capture that')
     self.__board.capture(piece, captured, self.__turn)
     self.__next_turn()
Esempio n. 2
0
    def get_possible_captures_for(self, piece: Piece) -> set:
        color = piece.get_color()
        king = self.__white_king if color == Piece.Color.WHITE else self.__black_king

        captures = piece.get_possible_captures(self.__board, self.__turn)

        if piece != king and king.is_check(self.__board, self.__turn):
            captures = list(
                filter(lambda c: self.__can_capture_save_king(piece, king, c),
                       captures))

        captures = set(
            filter(
                lambda c: not king.can_capture_cause_check(
                    self.__board, piece, c, self.__turn), captures))

        return set(map(lambda x: x.get_position(), captures))