Created
September 18, 2023 18:23
-
-
Save danielbdias/8c355f0cf6de461c586078a75a0f2ca8 to your computer and use it in GitHub Desktop.
Example of Gymnasium usage using random actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gymnasium as gym | |
env = gym.make("CartPole-v1") | |
observation, info = env.reset(seed=42) | |
for iteration in range(1000): | |
action = env.action_space.sample() # this is where you would insert your policy | |
observation, reward, terminated, truncated, info = env.step(action) | |
print('Current iteration: ', iteration) | |
print('Current state: ', observation) | |
print('Action taken: ', action) | |
print() | |
if terminated or truncated: | |
observation, info = env.reset() | |
env.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment