當前位置: 首頁>>代碼示例>>Python>>正文


Python Board.get_all_hits方法代碼示例

本文整理匯總了Python中chess.Board.get_all_hits方法的典型用法代碼示例。如果您正苦於以下問題:Python Board.get_all_hits方法的具體用法?Python Board.get_all_hits怎麽用?Python Board.get_all_hits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chess.Board的用法示例。


在下文中一共展示了Board.get_all_hits方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Example

# 需要導入模塊: from chess import Board [as 別名]
# 或者: from chess.Board import get_all_hits [as 別名]

#.........這裏部分代碼省略.........

        text_h = self.fm.height()
        text_w = max(map(self.fm.width, "12345678"))

        board_sz = min(sz.height() - text_h - self.board_text_space * 3, 
                       sz.width() - text_w - self.board_text_space * 3)

        board_and_text_w = text_w + self.board_text_space + board_sz
        board_and_text_h = text_h + self.board_text_space + board_sz

        y_start_pos = (sz.height() - board_and_text_h) / 2
        x_start_pos = (sz.width() - board_and_text_w) / 2

        step = float(board_sz) / 8
        half_step = int(step / 2)

        self.horizontal_lines_y_coords = [y_start_pos + int(i * step) for i in range(9)]
        vertical_start_x = x_start_pos + text_w + self.board_text_space
        self.vertical_lines_x_corrds = [vertical_start_x + int(i * step) for i in range(9)]

        # draw labels
        for text, curr_y in zip("87654321", self.horizontal_lines_y_coords[:-1]):
            painter.drawText(x_start_pos, curr_y + half_step + text_h / 2, text)
            #painter.drawRect(x_start_pos, curr_y - text_h, text_w, text_h)

        curr_y = y_start_pos + board_and_text_h - text_h / 2
        for text, curr_x in zip(board_letters, self.vertical_lines_x_corrds[:-1]):
            painter.drawText(curr_x + half_step - self.fm.width(text) / 2, curr_y, text)

        # draw black squares
        self.set_color(painter, lambda x, y: (x + y) % 2 == 1, "grey")

        for piece in self.board:
            tp, move, hit = piece.full_name(), self.board.get_all_moves(piece), self.board.get_all_hits(piece)

            if piece.pos == self.active_cell:
                self.draw_piece(painter, piece.pos, tp, list(move), list(hit), True)                
            else:
                self.draw_piece(painter, piece.pos, tp, "", "", False)

        self.draw_grid(painter, x_start_pos + text_w + self.board_text_space, y_start_pos, board_sz)

    def to_colored(self, piece):
        if piece[0] == "W":
            return self.white(piece[1:])
        else:
            assert piece[0] == "B"
            return self.black(piece[1:])

    def white(self, piece):
        return unicode(piece) + U"\u21D1"

    def black(self, piece):
        return unicode(piece) + U"\u21D3"

    def draw_piece(self, painter, pos, text, move_cells, hit_cells, collor_under_piece=False, use_image=True):

        hit_cells_set = set(hit_cells)
        move_cells_set =  set(move_cells)
        
        hit_only = hit_cells_set - move_cells_set
        move_only = move_cells_set - hit_cells_set
        hit_and_move = move_cells_set & hit_cells_set

        self.set_color(painter, list(hit_only), self.hit_cell_color, 125)
        self.set_color(painter, list(move_only), self.move_cell_color, 125)
開發者ID:ddovbii,項目名稱:python-classes,代碼行數:70,代碼來源:chess_gui.py


注:本文中的chess.Board.get_all_hits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。