コード例 #1
0
ファイル: pawn.py プロジェクト: mpunkenhofer/pychess
    def pawn_moves(self):
        if self.diagonally_pinned() or self.rank_pinned():
            return []

        m = []
        c = 1 if self.is_white() else -1
        p_x, p_y = self.position

        second_rank = self.board.get_first_rank(self.color) + 1 * c
        two_move_rank = p_y <= second_rank if self.is_white(
        ) else p_y >= second_rank

        if not self.history and self.board.in_board((p_x, p_y + 2 * c)) and \
                not self.pieces_between((p_x, p_y + 3 * c)) and two_move_rank:
            m.append(moves.Move(self, (p_x, p_y), (p_x, p_y + 2 * c)))

        if self.board.in_board((p_x, p_y + 1 * c)) and \
                not self.pieces_between((p_x, p_y + 2 * c)):
            if self.board.is_last_rank(self.color, (p_x, p_y + 1 * c)):
                m += self.generate_all_promotions((p_x, p_y),
                                                  (p_x, p_y + 1 * c))
            else:
                m.append(moves.Move(self, (p_x, p_y), (p_x, p_y + 1 * c)))

        return m
コード例 #2
0
    def get_moves(self):
        m = []
        squares = self.influenced_squares()
        p_x, p_y = self.position

        for s in squares:
            if self.protected_square(s):
                continue

            if s in self.board.pieces:
                if self.board.pieces[s].color != self.color:
                    m.append(
                        moves.Capture(self, (p_x, p_y), s,
                                      self.board.pieces[s]))
            else:
                m.append(moves.Move(self, (p_x, p_y), s))

        castle_short = self.short_castle()
        castle_long = self.long_castle()

        if castle_short:
            m.append(castle_short)

        if castle_long:
            m.append(castle_long)

        return m
コード例 #3
0
ファイル: bishop.py プロジェクト: mpunkenhofer/pychess
    def get_moves(self):
        if self.file_pinned() or self.rank_pinned():
            return []

        m = []
        p_x, p_y = self.position

        pining_piece = self.diagonal_pin_piece()

        if pining_piece and self.same_rising_diagonal(self, pining_piece):
            squares = self.get_rising_diagonal_squares()
        elif pining_piece and self.same_falling_diagonal(self, pining_piece):
            squares = self.get_falling_diagonal_squares()
        else:
            squares = self.influenced_squares()

        for s in squares:
            if s in self.board.pieces:
                if self.board.pieces[s].color != self.color:
                    if self.board.pieces[s] == self.board.get_enemy_king(
                            self.color):
                        m.append(moves.Attack(self, (p_x, p_y), s))
                    else:
                        m.append(
                            moves.Capture(self, (p_x, p_y), s,
                                          self.board.pieces[s]))
            else:
                m.append(moves.Move(self, (p_x, p_y), s))

        return m
コード例 #4
0
    def get_moves(self):
        if self.diagonally_pinned():
            return []

        m = []
        p_x, p_y = self.position

        if self.file_pinned():
            squares = self.get_file_squares()
        elif self.rank_pinned():
            squares = self.get_rank_squares()
        else:
            squares = self.influenced_squares()

        for s in squares:
            if s in self.board.pieces:
                if self.board.pieces[s].color != self.color:
                    if self.board.pieces[s] == self.board.get_enemy_king(
                            self.color):
                        m.append(moves.Attack(self, (p_x, p_y), s))
                    else:
                        m.append(
                            moves.Capture(self, (p_x, p_y), s,
                                          self.board.pieces[s]))
            else:
                m.append(moves.Move(self, (p_x, p_y), s))

        return m