当前位置: 首页>>代码示例>>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;未经允许,请勿转载。