開始使用免費開始

建立 Mountain Car 環境

最常見的 Gym 環境之一是 Mountain Car。目標是把動力不足的車子開上陡坡。由於引擎不夠強,無法一次就爬上去,所以需要透過前後來回加速來累積動能。你的任務是建立並設定這個環境。

本練習屬於課程

使用 Python 的 Gymnasium 進行強化學習

檢視課程

練習說明

  • gymnasium 函式庫以 gym 匿名導入。
  • 使用 Gym 函式庫建立一個 Mountain Car 環境,環境 ID 設為 MountainCarrender_mode 設為 'rgb_array'
  • 使用 seed42 重設環境,並取得 initial_state,其中包含兩個數值:車輛的位置與速度。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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)")
編輯並執行程式碼