始める無料で始める

Mountain Car 環境をセットアップする

Gym でもっとも一般的な環境のひとつが Mountain Car です。目的は、非力な車で急な坂を登り切ることです。エンジンだけでは一気に登れないため、車は前後に走って慣性をつける必要があります。あなたの課題は、この環境を作成して初期設定することです。

この演習はコースの一部です

Pythonで学ぶGymnasiumによるReinforcement Learning

コースを見る

演習の手順

  • gymnasium ライブラリを gym としてインポートします。
  • Gym ライブラリを使って Mountain Car 環境を作成し、環境IDを MountainCarrender_mode'rgb_array' に設定します。
  • seed42 を指定して環境をリセットし、車の位置と速度の2つの値を含む 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)")
コードを編集して実行