1

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

这甚至可以用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
4

1 回答 1

1

我建议检查强化学习的工作原理。核心思想是这样的——

强化学习是关于在特定情况下采取适当的行动来最大化奖励。

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

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

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

于 2020-07-24T14:04:44.980 回答