本文整理汇总了Python中cube.Cube.randomize方法的典型用法代码示例。如果您正苦于以下问题:Python Cube.randomize方法的具体用法?Python Cube.randomize怎么用?Python Cube.randomize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cube.Cube
的用法示例。
在下文中一共展示了Cube.randomize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Environment
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import randomize [as 别名]
class Environment(object):
# Initialize a random cube
def __init__(self, N):
self.N = N
self.cube = Cube(N=N)
def suffle(self, rand_nb=None, fixed_action=None):
if rand_nb is not None:
moves = self.cube.randomize(rand_nb)
return moves
self.perform_action(fixed_action)
return fixed_action
# Make a move and get a reward:
# 0 is the cube is not finish
# 1 is the cube is done
def perform_action(self, action):
[f, l, d] = action
self.cube.move(f, l, d)
return self.reward()
def reward(self,):
return self.cube.finish()
# if self.cube.finish():
# return 1.
# for i in range(6):
# if np.array_equal(self.cube.stickers[i, :, :], i * np.ones((self.N, self.N))):
# return 0.1
# return 0.
# Select a random_action
def random_action(self,):
f = np.random.randint(6)
l = np.random.randint(self.N)
d = 1 + np.random.randint(3)
return [f, l, d]
def get_state(self,):
return self.cube.stickers
示例2: Cube
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import randomize [as 别名]
if __name__ == "__main__":
cube = Cube()
window = Cube_graphics(cube)
while True:
if window.scene.kb.keys:
s = window.scene.kb.getkey()
# w, a, s, d, o, p
if (s == 'w'):
window.rot_X(1)#c.rotate('X', 1)
elif (s == 's'):
window.rot_X(-1)#c.rotate('X', -1)
elif (s == 'a'):
window.rot_Y(1)#c.rotate('Y', 1)
elif (s == 'd'):
window.rot_Y(-1)#c.rotate('Y', -1)
elif (s == 'o'):
cube.reset()
window.update_faces()
elif (s == 'p'):
cube.randomize()
window.update_faces()
elif (s == 'up'):
window.turn_R(1)#c.turn('R', 1)
elif (s == 'down'):
window.turn_R(-1)#c.turn('R', -1)
elif (s == 'left'):
window.turn_U(1)#c.turn('U', 1)
elif (s == 'right'):
window.turn_U(-1)#c.turn('U', -1)