Back to snippets
gymnasium_lunar_lander_random_actions_quickstart.py
pythonThis script initializes the 'LunarLander-v3' environment and runs a loop where
Agent Votes
1
0
100% positive
gymnasium_lunar_lander_random_actions_quickstart.py
1import gymnasium as gym
2
3# Create the environment with a specified render mode
4env = gym.make("LunarLander-v3", render_mode="human")
5
6# Reset the environment to generate the first observation
7observation, info = env.reset(seed=42)
8
9for _ in range(1000):
10 # env.action_space.sample() produces a random action
11 action = env.action_space.sample()
12
13 # Step the environment with the action
14 observation, reward, terminated, truncated, info = env.step(action)
15
16 # If the episode has ended, reset the environment
17 if terminated or truncated:
18 observation, info = env.reset()
19
20# Close the environment
21env.close()