当前位置: 首页>>代码示例>>Python>>正文


Python Piece.rotate_right方法代码示例

本文整理汇总了Python中piece.Piece.rotate_right方法的典型用法代码示例。如果您正苦于以下问题:Python Piece.rotate_right方法的具体用法?Python Piece.rotate_right怎么用?Python Piece.rotate_right使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在piece.Piece的用法示例。


在下文中一共展示了Piece.rotate_right方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test1

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import rotate_right [as 别名]
def test1():
    b = Board(10,10)
    base=Board(data='0,0,0,1,1,1,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0;0,0,0,2,2,0,0,0,0,0;0,0,0,0,2,2,0,0,0,0;0,0,0,2,2,0,0,0,0,0;0,0,0,0,2,2,0,0,0,0;0,0,0,0,2,2,0,0,0,0;0,0,0,2,2,2,0,0,0,0;0,0,0,2,2,2,0,0,0,0')
    p1 = Piece('I')
    p2 = Piece('I')
    p2.rotate_right()
    loc1 = (0,0)
    loc2 = (2,2)

    path = b.get_path(p1, loc1, p2, loc2)

    result = b.get_feature_vector()
    print result
开发者ID:mrtong96,项目名称:aigames_blockbattle,代码行数:15,代码来源:board.py

示例2: get_valid_positions

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import rotate_right [as 别名]
    def get_valid_positions(self, piece_type):
        valid_positions = []
        piece = Piece(piece_type)

        for i in range(NUM_ROTATIONS[piece_type]):

            blocks = piece.get_locations()

            x_blocks, y_blocks = zip(*blocks)
            p_minx = min(x_blocks)
            p_maxx = max(x_blocks)
            p_miny = min(y_blocks)
            p_maxy = max(y_blocks)

            lowest_blocks = filter(lambda x: x[1] == p_miny, blocks)

            # refers to the top left corner of the block (0,0)
            for y in range(-p_miny, self.height - p_maxy):
                for x in range(-p_minx, self.width - p_maxx):
                    shift_blocks = map(lambda b: (x + b[0], y + b[1]), blocks)

                    # finds conflicts of space
                    conflict = False
                    for x_block, y_block in shift_blocks:
                        if self.data[y_block][x_block] > 1:
                            conflict = True
                            break
                    if conflict:
                        continue

                    floor_exists = False
                    for x_block, y_block in shift_blocks:
                        if y_block == self.height - 1 or self.data[y_block + 1][x_block] > 1:
                            floor_exists = True
                            break

                    if not floor_exists:
                        continue

                    valid_positions.append((Piece(piece_type, right_rotations=i), x, y))

            piece.rotate_right()

        return valid_positions
开发者ID:mrtong96,项目名称:aigames_blockbattle,代码行数:46,代码来源:board.py


注:本文中的piece.Piece.rotate_right方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。