mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-11 22:13:55 +01:00
feat: update requirements, inital code snippet
This commit is contained in:
parent
297fce2a8a
commit
78ea388285
28
main.py
28
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()
|
||||||
@ -8,3 +8,4 @@ dependencies:
|
|||||||
- moviepy
|
- moviepy
|
||||||
- numpy
|
- numpy
|
||||||
- python=3.9
|
- python=3.9
|
||||||
|
- pygame
|
||||||
|
|||||||
1
vid/rl-video-episode-3.meta.json
Normal file
1
vid/rl-video-episode-3.meta.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"step_id": 600, "episode_id": 3, "content_type": "video/mp4"}
|
||||||
BIN
vid/rl-video-episode-3.mp4
Normal file
BIN
vid/rl-video-episode-3.mp4
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user