-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecution.py
More file actions
20 lines (18 loc) · 765 Bytes
/
execution.py
File metadata and controls
20 lines (18 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import time
def simulate(actor, environment, max_steps=1000, render=False, fps=30):
"""Executes a full episode of actor in environment, for at most max_steps time steps
If render is True, will render simulation on screen at ~fps frames per second."""
total_reward = 0
observation = environment.reset()
frame_delay = 1.0 / fps # actually need seconds per frame for sleep method
done = False
steps = 0
while not done and steps < max_steps:
if render:
environment.render()
time.sleep(frame_delay)
action = actor.react_to(observation)
observation, reward, done, info = environment.step(action)
steps += 1
total_reward += reward
return total_reward