| 92 | |
| 93 | |
| 94 | def play_one(env, model, eps, gamma): |
| 95 | observation = env.reset() |
| 96 | done = False |
| 97 | totalreward = 0 |
| 98 | iters = 0 |
| 99 | while not done and iters < 2000: |
| 100 | # if we reach 2000, just quit, don't want this going forever |
| 101 | # the 200 limit seems a bit early |
| 102 | action = model.sample_action(observation, eps) |
| 103 | prev_observation = observation |
| 104 | observation, reward, done, info = env.step(action) |
| 105 | |
| 106 | if done: |
| 107 | reward = -200 |
| 108 | |
| 109 | # update the model |
| 110 | next = model.predict(observation) |
| 111 | # print(next.shape) |
| 112 | assert(next.shape == (1, env.action_space.n)) |
| 113 | G = reward + gamma*np.max(next) |
| 114 | model.update(prev_observation, action, G) |
| 115 | |
| 116 | if reward == 1: # if we changed the reward to -200 |
| 117 | totalreward += reward |
| 118 | iters += 1 |
| 119 | |
| 120 | return totalreward |
| 121 | |
| 122 | |
| 123 | def main(): |