BaşlayınÜcretsiz Başlayın

Setting up a Mountain Car environment

One of the most common Gym environments is Mountain Car, where the goal is to drive an underpowered car up a steep hill. The car's engine isn't strong enough to climb the hill in a single pass, so the car needs to build up momentum by driving back and forth. Your task is to create and set up this environment.

Bu egzersiz

Reinforcement Learning with Gymnasium in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import the gymnasium library as gym.
  • Create a Mountain Car environment using the Gym library setting the environment ID as MountainCar and the render_mode as 'rgb_array'.
  • Reset the environment using a seed of 42 and get the initial_state which contains two values: the position and velocity of the car.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Import the gymnasium library
____

# Create the environment
env = ____

# Get the initial state
initial_state, info = ____

position = initial_state[0]
velocity = initial_state[1]

print(f"The position of the car along the x-axis is {position} (m)")
print(f"The velocity of the car is {velocity} (m/s)")
Kodu Düzenle ve Çalıştır