MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / play_one_episode

Function play_one_episode

examples/DeepQNetwork/common.py:17–38  ·  view source on GitHub ↗
(env, func, render=False)

Source from the content-addressed store, hash-verified

15
16
17def play_one_episode(env, func, render=False):
18 def predict(s):
19 """
20 Map from observation to action, with 0.01 greedy.
21 """
22 s = np.expand_dims(s, 0) # batch
23 act = func(s)[0][0].argmax()
24 if random.random() < 0.01:
25 spc = env.action_space
26 act = spc.sample()
27 return act
28
29 ob = env.reset()
30 sum_r = 0
31 while True:
32 act = predict(ob)
33 ob, r, isOver, info = env.step(act)
34 if render:
35 env.render()
36 sum_r += r
37 if isOver:
38 return sum_r
39
40
41def play_n_episodes(player, predfunc, nr, render=False):

Callers 2

play_n_episodesFunction · 0.70
runMethod · 0.70

Calls 4

renderMethod · 0.80
predictFunction · 0.70
resetMethod · 0.45
stepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…