Racing AI (with complications)

Started by
7 comments, last by me22 18 years, 5 months ago
Having read through some of the other racing AI threads on these forums, I've noticed that most of them involve creating an AI that follows a developer-specified optimal racing line. But my tracks are hideously loopy: My Journal, for Screenshots. I really would rather not have to manually create a racing line for each track. Mostly because I don't even know that I could FIND an ideal sort of racing line. Heck, I'm not even sure that, as bad as I actually am at racing games (don't let the fact that I'm writing one fool you), I could even DRIVE a fairly optimal line. And another wrinkle: In addition to the steering and the accelerator (which includes the brakes), there's also a "slide" button, which turns off the motion dampening in the car's sideways movement (i.e. holding "slide" allows the car to continue moving in the direction it's going, even if the car turns). I'd like the AI to be able to use that feature, though I won't be terribly heartbroken if it can't. Is there any other sort of way to generate a near-optimal racing line? Or to make an AI that can use other attributes of the track to drive such a track? Suggestions? I'm new to this whole AI business, so it could be (And is even likely) that I'm missing something horrendously obvious. Please feel free to point it out. Thanks much, Josh
Advertisement
I always see this type of problem as follows: Discretize the set of decissions that the AI can take at any given time, discretize the time intervals at which decissions are made, look at the problem as a search in a directed graph. If you can somehow discretize the states and then "round" the intermediate results to the discrete states, your search can be sped up tremendously.

You can precalculate optimal paths this way, or you can have the AI take the decissions in real time, although I am not sure if this is practical.

For a racing game, I would imagine that the state can be described by:
* how far you are from the goal (or some other single-number indicator of where you are in the race),
* where you stand on the track in the left-right sense,
* what direction you are moving in,
* how fast you are going
and perhaps you need to add another number with the direction that the car is pointing to, since you have the "slide" option.

So if you consider 10 positions within the left-right range, 64 directions of movement, 16 speeds and maybe another 32 directions for where the car is looking at, for every "slice" of the racetrack you need 320K nodes. The good news is that you can start with the last slice of the racetrack (the goal), where you know exactly how long it's going to take you to the goal (0). Then computing the slice before that one is really easy. You keep going back like this, and it is always easy to find what the cost of getting from any node to the goal is, given that you know the cost of getting there from all the positions in front of you; just imagine you take each one of the actions and look up where you would end up on the next "turn".

This algorithm only requires keeping a few slices in memory at any given time (as many as can be traversed in a single turn at maximum speed). This is a lot of data, so in the end you will have to reduce it to something practical, like storing just one (or several) good paths.

I hope this helps.
First, you could use an algorithm (I prefer A*) to find sort out the path, and then do something like this: "if the angle of turn is more then n degrees, then enable 'slide' feature"...

-zubair-
PS: sorry if i was too brief
Amps
Grab a copy of Ai Game Programming Wisdom 2, theres an article in there on Generating Racing Lines automatically. Page 485
Thanks for the help, everyone!

A copy of AI Game Programming Wisdom 2 is on order :D
While waiting for your book check out RARS and some of the cars people have done for that (may need to google for them, look for K1999 by Remi Coulom for a really awesome car, can't find the paper right now though).

Under algorithms you can see how someone used A* for it.

Here is a reinforcement learning example for RARS. Also check into neural-nets, which I hear worked quite well for Colin McCrae Rally.
About that sliding thing, I recently implemented AI players in my top-down racing game Turbo Sliders. As the name suggests, sliding is an integral part of the game and it surely did add complexity to the AI code. AI cars try to follow one of 10-20 racing lines (generated by human driving) but it was quite hard to make it work with the cars that slide a lot. Are you aware of other racing games with AI where there would be as much sliding?
Drilian, I would be tempted to just hand each track to a bunch of playtesters and record the paths they take, recording how they use the controls and possibly tweaking them slightly, to be used later by AI controlled characters. It might also be worth seeing how far you can go (literally) with simple steering behaviours.

And bear in mind that, relative to the track itself, the racing line is still just 2D (assuming I understand your game). The problem is easier to think about in those terms, as I believe the AI Wisdom article will cover.

PS. Ande, I love Turbo Sliders. Great game! :)
I was skimming your journal and noticed:

Quote:Original post by Drilian
Plus, the car has a force-field (or whatever they will call those things in the future), so the walls actually bounce the car more like a pinball bumper than in a realistic fashion (the force field applies some bounce force).


Combind that with sliding, and a perfect AI might end up finding some very unlikey--but very fast--ways of bouncing through corners, which you might not actually even want.

You also mention:
Quote:Original post by Drilian
Each track segment gets the following attributes (which are relative to the track segment's initial orientation):
Length - This represents the angle of the track relative to the in-game representation of the north star. That, or just the length of the track down the middle. I can never remember which is which.
Width - Determines what the width will be by the end of the section of track (the previous section determines the initial width).
Curve - The amount of curvature of the track. A negative curve is to the left, positive is to the right. A 360 degree curve is, as expected, a full rotation.
Horizontal Skew - This is how much the track strafes to the side (along a sinusoidal sort of path) across its length. It's like a lane-change. Only the pavement is changing lanes, not the car.
Incline Curve - This is the circular incline of the track. A 360 degree value of this would be a full loop. Positive is up, negative is down.
Vertical Skew - Similar to the horizontal skew, only vertical. How's THAT for descriptive?
Twist - This is how much the track rolls to one side or the other along its length, which modifies the orientation for the next segment
Bank - This is similar to twist, except it raises one side instead of twisting around the middle, and the orientation remains unchanged in the next segment of track (this is to allow for banked curves, which I wouldn't want to curve upwards because of the bank or something stupid like that).


You might be able to use an abstraction of those for the current and next segment as inputs to a neural network. Alternatively, some sort of FuSM might also work, although the outputs aren't all that orthogonal, so it isn't the greatest place for a FuSM.

This topic is closed to new replies.

Advertisement