feat: update requirements, inital code snippet

This commit is contained in:
Krzysztof Rudnicki 2023-05-21 15:19:00 +02:00
parent 297fce2a8a
commit 78ea388285
4 changed files with 30 additions and 0 deletions

28
main.py
View File

@ -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()

View File

@ -8,3 +8,4 @@ dependencies:
- moviepy
- numpy
- python=3.9
- pygame

View File

@ -0,0 +1 @@
{"step_id": 600, "episode_id": 3, "content_type": "video/mp4"}

BIN
vid/rl-video-episode-3.mp4 Normal file

Binary file not shown.