-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4.py
More file actions
35 lines (29 loc) · 933 Bytes
/
test4.py
File metadata and controls
35 lines (29 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gym
import matplotlib.pyplot as plt
import numpy as np
import os
import shutil
#os.environ['DISPLAY'] = 'localhost:0.0'
#from IPython import display
import pyvirtualdisplay
pyvirtualdisplay.Display(visible=0,size=(1400,900)).start()
try:
shutil.rmtree("videos")
except FileNotFoundError:
pass
os.mkdir("videos")
env = gym.make('CarRacing-v0') # env_name = "Pendulum-v0"
for i_episode in range(5):
observation = env.reset()
for t in range(100):
#plt.imshow(os.path.join('videos', '-'.join(str(t)) + '.png'),
# env.render(mode='rgb_array'))
#display.display(plt.gcf())
#display.clear_output(wait=True)
print(t)
action = env.action_space.sample() # take a random action
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
env.close()