本文整理汇总了Python中cube.Cube.move方法的典型用法代码示例。如果您正苦于以下问题:Python Cube.move方法的具体用法?Python Cube.move怎么用?Python Cube.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cube.Cube
的用法示例。
在下文中一共展示了Cube.move方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Environment
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import move [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: enumerate
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import move [as 别名]
# Show good examples in the replay memory with probability
# "good_examples"
r = np.random.uniform(0., 1., 1)
if r < args.good_examples:
for i, move in enumerate(reversed(moves)):
r_move = reverse_action(move)
# Make the move
if i == 0:
x_t = np.copy(env.get_state())
y_t = np.copy(env.get_state())
else:
x_t = np.copy(x_tp1)
y_t = np.copy(x_tp1)
cube = Cube(stickers=y_t)
cube.move(r_move[0], r_move[1], r_move[2])
x_tp1 = np.copy(cube.stickers)
# Compute reward
reward = args.gamma ** (len(moves) - i - 1)
# Shift action
r_move[1] += 6
r_move[2] += 6 + N -1
fill_replay_memory(replay_memory,
args.max_replay_memory,
[x_t, r_move, reward, x_tp1])
finish_episode = False
t = 0