(model, env, eps, gamma, lambda_)
| 83 | |
| 84 | # returns a list of states_and_rewards, and the total reward |
| 85 | def play_one(model, env, eps, gamma, lambda_): |
| 86 | observation = env.reset() |
| 87 | done = False |
| 88 | totalreward = 0 |
| 89 | states_actions_rewards = [] |
| 90 | iters = 0 |
| 91 | model.reset() |
| 92 | while not done and iters < 1000000: |
| 93 | action = model.sample_action(observation, eps) |
| 94 | prev_observation = observation |
| 95 | observation, reward, done, info = env.step(action) |
| 96 | |
| 97 | if done: |
| 98 | reward = -300 |
| 99 | |
| 100 | # update the model |
| 101 | next = model.predict(observation) |
| 102 | assert(next.shape == (1, env.action_space.n)) |
| 103 | G = reward + gamma*np.max(next[0]) |
| 104 | model.update(prev_observation, action, G, gamma, lambda_) |
| 105 | |
| 106 | states_actions_rewards.append((prev_observation, action, reward)) |
| 107 | |
| 108 | if reward == 1: # if we changed the reward to -200 |
| 109 | totalreward += reward |
| 110 | |
| 111 | iters += 1 |
| 112 | |
| 113 | # if iters > 0 and iters % 1000 == 0: |
| 114 | # print(iters) |
| 115 | # if done: |
| 116 | # print "finished in < 1000 steps!" |
| 117 | |
| 118 | return states_actions_rewards, totalreward |
| 119 | |
| 120 | |
| 121 | if __name__ == '__main__': |
no test coverage detected