(model, env, eps, gamma, lambda_)
| 76 | |
| 77 | # returns a list of states_and_rewards, and the total reward |
| 78 | def play_one(model, env, eps, gamma, lambda_): |
| 79 | observation = env.reset() |
| 80 | done = False |
| 81 | totalreward = 0 |
| 82 | iters = 0 |
| 83 | # while not done and iters < 200: |
| 84 | while not done and iters < 10000: |
| 85 | action = model.sample_action(observation, eps) |
| 86 | prev_observation = observation |
| 87 | observation, reward, done, info = env.step(action) |
| 88 | |
| 89 | # update the model |
| 90 | Qnext = model.predict(observation) |
| 91 | assert(Qnext.shape == (1, env.action_space.n)) |
| 92 | G = reward + gamma*np.max(Qnext[0]) |
| 93 | model.update(prev_observation, action, G, gamma, lambda_) |
| 94 | |
| 95 | totalreward += reward |
| 96 | iters += 1 |
| 97 | |
| 98 | return totalreward |
| 99 | |
| 100 | |
| 101 | if __name__ == '__main__': |
no test coverage detected