-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_env.py
39 lines (32 loc) · 975 Bytes
/
test_env.py
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
36
37
38
39
import cv2
import numpy as np
from src.env import create_train_env
def main():
# 获取游戏
env = create_train_env(game="SuperMarioBros-Nes")
print(env.observation_space.shape)
print(env.action_space.n)
obs = env.reset()
while True:
# 游戏生成的随机动作,int类型数值
action = env.action_space.sample()
# 执行游戏
obs, reward, terminal, info = env.step(action)
# 显示连续动作
obs = np.squeeze(obs)
obses = obs[0]
for i in range(1, obs.shape[0]):
obses = np.hstack([obses, obs[i]])
cv2.imshow('obes', obses)
cv2.waitKey(1)
env.render()
print("=" * 50)
print("action:", action)
print("obs shape:", obs.shape)
print("reward:", reward)
print("terminal:", terminal)
print("info:", info)
if terminal:
obs = env.reset()
if __name__ == "__main__":
main()