MCPcopy Index your code
hub / github.com/rlcode/reinforcement-learning / run_test_loop

Function run_test_loop

2-cartpole/env.py:45–62  ·  view source on GitHub ↗

Replay episodes forever using the supplied action picker. `get_action(state: np.ndarray) -> int`.

(env, get_action)

Source from the content-addressed store, hash-verified

43
44
45def run_test_loop(env, get_action):
46 """Replay episodes forever using the supplied action picker.
47
48 `get_action(state: np.ndarray) -> int`.
49 """
50 while True:
51 state, _ = env.reset()
52 state = np.array(state, dtype=np.float32)
53 done = False
54 score = 0
55 while not done:
56 quit_if_window_closed(env)
57 action = get_action(state)
58 next_state, reward, terminated, truncated, _ = env.step(action)
59 done = terminated or truncated
60 state = np.array(next_state, dtype=np.float32)
61 score += reward
62 print(f"test score: {score}")

Callers 3

2-a2c.pyFile · 0.90
3-ppo.pyFile · 0.90
1-dqn.pyFile · 0.90

Calls 3

quit_if_window_closedFunction · 0.70
resetMethod · 0.45
stepMethod · 0.45

Tested by

no test coverage detected