是否可以使用神经网络/人工智能来'optimise'比赛所需的时间?



程序完成后,将使用人工智能获得尽可能快的时间。汽车可以加速、刹车或匀速行驶。代码中会有一些部分(代表弯道(,其中速度必须等于或低于某个值(取决于弯道有多紧(,我希望程序能够决定何时是加速、制动和匀速移动的最佳时刻。

这对python来说可能吗?你能创建一个神经网络来逐渐获得更好的时间吗?如果是这样的话,我该怎么做呢?

谢谢!

import time
x = 0
def TrackSimulation(distance, speed, acceleration, loopbreak, time1):
while loopbreak == 1:
if x == 1:
acceleration = 9
elif x == 2:
acceleration = -9
elif x == 0:
acceleration = 0
else:
print("Error")
if distance >= 0 and distance < 80:
speed = (speed) + ((acceleration) * 0.1)
distance = (distance) + ((speed) * 0.1)
time1 = time1 + 0.1
print((speed), " M/s")
print((distance), "M")
time.sleep(0.1)
elif distance >= 80 and distance <= 110:
if speed >= 30:
print("Too fast!")
loopbreak = 2
break
else:
print("You are in the speed checker")
speed = (speed) + ((acceleration) * 0.1)
distance = (distance) + ((speed) * 0.1)
time1 = time1 + 0.1
print((speed), " M/s")
print((distance), "M")
time.sleep(0.1)
elif distance >= 110 and distance < 200:
speed = (speed) + ((acceleration) * 0.1)
distance = (distance) + ((speed) * 0.1)
time1 = time1 + 0.1
print((speed), " M/s")
print((distance), "M")
time.sleep(0.1)
elif distance >= 200:
print("race over")
finaltime = round((time1), 3)
print("This was your time,", (finaltime))
loopbreak = 2
break

我建议你看看强化学习是如何工作的。核心思想是这个-

强化学习是指在特定情况下采取适当的行动以最大限度地提高回报。

因此,例如,在您的情况下,您有这条赛道,您需要构建一个算法,使汽车能够在最短的时间内达到目标。这意味着你需要训练一个强化学习模型,最大限度地减少达到目标所需的时间。该模型将有一些输入参数,如速度、加速度、左转向、右转向、断开等。它将从在该输入空间中采取随机行动开始,在保持正轨并尽量减少所需时间的同时努力达到最终目标。

Open AI Gym在python中提供了一套优秀的工具来练习和学习强化算法,如q-learning。它包含了在python中实现的各种游戏,允许您构建自己的模型,并尝试针对奖励训练您的参与者。看看这个赛车游戏在那里实现了。

这是一段关于强化学习的视频,用马里奥卡丁车训练马里奥赢得比赛。

最新更新