-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gym_3.py
More file actions
30 lines (22 loc) · 770 Bytes
/
test_gym_3.py
File metadata and controls
30 lines (22 loc) · 770 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
import gymnasium as gym
env = gym.make("CartPole-v1", render_mode="human")
print(env.observation_space)
print(env.action_space)
print(env.action_space.sample())
print(env.action_space.sample())
print(env.observation_space.low)
print(env.observation_space.high)
env.reset()
for i in range(100):
done = False
game_rew = 0
while not done:
action = env.action_space.sample()
obs, rew, terminated, truncated, info = env.step(action)
game_rew += rew
# Combine `terminated` (episode ended in a terminal state)
# and `truncated` (time limit or another truncation condition)
done = terminated or truncated
if done:
print(f"Episode {i} finished, reward: {game_rew}")
env.reset()