AI Learns To Drive Trackmania

Machine learning has long been a topic of interest for humanity, but only in recent years have we had broad access to great computing power to enable to the average person to dive in. [Yosh] recently decided to put an AI to work learning how to race in Trackmania.

After early experiments with supervised learning, [Yosh] decided to implement a genetic algorithm to produce an AI to drive in the game. The AI takes distance from the track walls as an input, and has steering and accelerator values as an output. Starting with 100 AIs in generation 1, [Yosh] iterated by choosing the AIs that covered the longest distance in 13 seconds. Once the AIs started to get the hang of the first few corners, he changed the training to instead prioritize the lowest time taken to traverse each of the checkpoints along the track.

The AI improved over time, and over 100 generations, got down to a 23.48s time on the test track, versus 19.63s for [Trabadia], a talented human. We’d love to see how much better the AI could do with more training. [Yosh] is trying more experiments, like providing extra feedback in the AI fitness function to keep it from hitting the walls. It’s not the first time we’ve seen a genetic algorithm used to train a racing AI, either. Video after the break.

25 thoughts on “AI Learns To Drive Trackmania

        1. Around 8:30 in the video shows this best. It is learning the first half of the track and uses what it learned to drive in the new section of track that it has not seen before. So yes it is learning to drive, it is just going to do worse with unfamiliar track just like an organic neural network.

  1. I think the result would have been better if he had used the car speedometer as part of the fitness function. Keeping the value as high as possible for as long as possible could have provided valuable information. Also, only being able run the track in realtime is a serious problem. A simulation of the game (even if an absolute bare minimum) would have enabled him to run millions of generations in an equal amount of time.

    1. for me it also looks that the ai has not enough data, fastest actor is keeping in the middle of the track even in the corners, because it does not know how the track looks like in front. Ffor me it looks that it can’t distinguish between left and right turn and should get more data from the front – maybe few deg left and right from the middle beam.

  2. The simulated drivers don’t anticipate the best positioning of the car as well as the real driver. Seems like a better formula for track position and speed would help. Also, once a human runs the track the upcoming curves are known. Perhaps adding a track layout to the AI vehicles would be more fair. Good Job

    1. I don’t see much obvious anticipation at all, in the zoom out, they look like a bucket of marbles dumped down a swervy marble run. Like you’ve taught them the basics of fluid dynamics rather than how to drive.

    1. after watching the video it seems like the AI cant handle long straights correctly cause it doesn’t get data about them. it’ll go full out and hit the curb in the next corner.

    2. It will not.

      Trackmania is actually even more complex than actual racing, e.g. F1. Yes, it does lack traffic, but it’s got verticality. There are heaps of tracks out there in Trackmania which have jumps and clips incorporated in them. And some tracks are so complex that you have to know the exact layout down to the pixel, position your car in turn x one certain way to make a jump in n turns, apply brakes midair to land on a specific spot to be able to take another turn perfectly.

      No way in hell is an “AI” – which in this case isn’t more than a fluid simulation as others said – going to be able to accomplish this.

  3. seems like it would have done better by just checking two points in front of it for color.
    always accelerate and if left or right point is white turn opposite direction until it is no longer white.

  4. This is not AI, this is Machine Learning. No, they are not the same. Yes, understanding the difference between them and clearly communicating is important. Something very similar to this was done way back in 2015 with MarI/O.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.