Skip to content

Instantly share code, notes, and snippets.

@danielbdias
Created September 18, 2023 18:23
Show Gist options
  • Save danielbdias/8c355f0cf6de461c586078a75a0f2ca8 to your computer and use it in GitHub Desktop.
Save danielbdias/8c355f0cf6de461c586078a75a0f2ca8 to your computer and use it in GitHub Desktop.
Example of Gymnasium usage using random actions
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