本文整理汇总了Python中piece.Piece.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Piece.copy方法的具体用法?Python Piece.copy怎么用?Python Piece.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类piece.Piece
的用法示例。
在下文中一共展示了Piece.copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSuccessors
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import copy [as 别名]
def getSuccessors(self, cur_state):
cur_piece_type, cur_rotations, cur_loc = cur_state
cur_piece = Piece(cur_piece_type, right_rotations=cur_rotations)
possible_actions = ['up', 'left', 'right', 'turnleft', 'turnright']
state_action_pairs = []
for action in possible_actions:
if action == 'up' or action == 'left' or action == 'right':
if action == 'up':
shifted_loc = (cur_loc[0], cur_loc[1] - 1)
elif action == 'left':
shifted_loc = (cur_loc[0] - 1, cur_loc[1])
else:
shifted_loc = (cur_loc[0] + 1, cur_loc[1])
piece_copy = cur_piece.copy()
blocks = piece_copy.get_locations()
blocks = map(lambda x: (x[0] + shifted_loc[0], x[1] + shifted_loc[1]), blocks)
else:
shifted_loc = cur_loc
piece_copy = cur_piece.copy()
if action == 'turnleft':
piece_copy.rotate_left()
else:
piece_copy.rotate_right()
blocks = piece_copy.get_locations()
append = True
for x_block, y_block in blocks:
#if x_block < 0 or y_block < 0 or\
if x_block < 0 or y_block < -cur_piece.size or\
x_block >= self.board.width or y_block >= self.board.height:
append = False
break
elif y_block >= 0 and self.board.data[y_block][x_block] > 1:
append = False
break
if append:
state_action_pairs.append(((piece_copy._type, piece_copy.right_rotations, shifted_loc), action))
return state_action_pairs