(env, pmodel, vmodel, gamma)
| 160 | |
| 161 | |
| 162 | def play_one_td(env, pmodel, vmodel, gamma): |
| 163 | observation = env.reset() |
| 164 | done = False |
| 165 | totalreward = 0 |
| 166 | iters = 0 |
| 167 | |
| 168 | while not done and iters < 2000: |
| 169 | # if we reach 2000, just quit, don't want this going forever |
| 170 | # the 200 limit seems a bit early |
| 171 | action = pmodel.sample_action(observation) |
| 172 | prev_observation = observation |
| 173 | observation, reward, done, info = env.step(action) |
| 174 | |
| 175 | # if done: |
| 176 | # reward = -200 |
| 177 | |
| 178 | # update the models |
| 179 | V_next = vmodel.predict(observation)[0] |
| 180 | G = reward + gamma*V_next |
| 181 | advantage = G - vmodel.predict(prev_observation) |
| 182 | pmodel.partial_fit(prev_observation, action, advantage) |
| 183 | vmodel.partial_fit(prev_observation, G) |
| 184 | |
| 185 | if reward == 1: # if we changed the reward to -200 |
| 186 | totalreward += reward |
| 187 | iters += 1 |
| 188 | |
| 189 | return totalreward |
| 190 | |
| 191 | |
| 192 |
nothing calls this directly
no test coverage detected