diff --git a/main.py b/main.py index e69de29b..a907164c 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,28 @@ +import gymnasium as gym + +if __name__ == "__main__": + # init env + env = gym.make("MountainCar-v0", render_mode="rgb_array") + + # wrapper to record the video at 3rd episode and saves it to the folder + # 'vid' + env = gym.wrappers.RecordVideo( + env, video_folder="vid", episode_trigger=lambda x: x == 3 + ) + + # an episode ends if goal is reached or other game ending factors (e.g. + # reached max steps) + n_episodes = 4 + for episode in range(n_episodes): # iterate episodes + state, info = env.reset() # reset the env to an initial state + done = False # boolean to stop an episode + + while not done: # iterate steps + # randomly choose a sample + action = env.action_space.sample() + # take the action (step) and observe the state and reward + next_state, reward, terminated, truncated, info = env.step(action) + # condition to stop an episode + done = terminated or truncated + + env.close() diff --git a/requirements.yml b/requirements.yml index cb483ef2..de1caf6d 100644 --- a/requirements.yml +++ b/requirements.yml @@ -8,3 +8,4 @@ dependencies: - moviepy - numpy - python=3.9 + - pygame diff --git a/vid/rl-video-episode-3.meta.json b/vid/rl-video-episode-3.meta.json new file mode 100644 index 00000000..4e13da84 --- /dev/null +++ b/vid/rl-video-episode-3.meta.json @@ -0,0 +1 @@ +{"step_id": 600, "episode_id": 3, "content_type": "video/mp4"} \ No newline at end of file diff --git a/vid/rl-video-episode-3.mp4 b/vid/rl-video-episode-3.mp4 new file mode 100644 index 00000000..12d1ce2d Binary files /dev/null and b/vid/rl-video-episode-3.mp4 differ