ตั้งค่า Mountain Car environment
หนึ่งใน Gym environment ที่ได้รับความนิยมมากที่สุดคือ Mountain Car ซึ่งมีเป้าหมายให้รถยนต์ที่มีกำลังเครื่องยนต์จำกัดขับขึ้นเนินชันได้สำเร็จ เนื่องจากเครื่องยนต์ไม่แรงพอที่จะไต่เนินได้ในครั้งเดียว รถจึงต้องสร้างแรงโมเมนตัมด้วยการขับไปมาก่อน ในแบบฝึกหัดนี้ให้สร้างและตั้งค่า environment ดังกล่าว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Reinforcement Learning with Gymnasium ใน Python
คำแนะนำการฝึกหัด
- นำเข้าไลบรารี
gymnasiumในชื่อgym - สร้าง Mountain Car environment โดยใช้ Gym library พร้อมกำหนด environment ID เป็น
MountainCarและrender_modeเป็น'rgb_array' - รีเซ็ต environment โดยใช้
seedเป็น42และรับค่า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)")