This link is not really what I used to implement the AI, but gave me a good overview of some trends:
http://privatewww.essex.ac.uk/~rdenar/Togelius2007Towards.pdfThis one gave me a lot of ideas about my CarDriver agent and how to implement thae tracks:
http://www.vagamelabs.com/static-bits/drivatars-an-artificial-intelligence-system-for-racing-g.htmThe last one doesn't really expose any implementation details, but is quite interesting.
My implementation is REALLY simple, but I liked the results and you'll see it in action on the video I'll post this weekend. Some things:
- For AI cars, tracks are (as in most race games) a collection of WayPoints, in my case each waypoint is a Large jME sphere (not in the scene graph, so not drawn)
- Each car has, at any time, a reference to the current waypoint it has to go to.
- I only have to test collisions of the car with its current waypoint.
- When reaching the waypoint, the car references the next one and so on.
This is the basics... How to make it work is the key. Some more considerations:
- Each car allways tries to turn towards the waypoint (unless trying to pass or avoid something else - later)
- Each waypoint has an attribute with its IDEAL speed for that point (this is really necessary for the car to make tight turns)
- Each car always acclerate to the next waypoint, and when near it brakes (proportionally to the distance) to the ideal speed.
- This is enough to make them follow the track and make very good times... Just have to calibrate the waypoint's location and speed.
- I do this calibration by recording some laps I make myself (I'm quite good at racing games -

)
The style part:
- When turning towards the next waypoint, each car steers its wheels proportionally to the relactive angle (facing direction vs. where to go to -vector3f vector3f)
- This would make them DEADLY stable and fast, so I introduce a random style factor. Each car has a coeficient of agressivness, which makes it turn more than it needs... That makes it occilate more than others (and the same happens when trying to pass)
The other stuff:
Each car always tests if it'd be efficient to fire against some other in front of it. Does it when it's almost in front (so doesn't miss) and when the car is not so near, maybe staying in the way.
When near the car in front, tries to pass, to the right or left, depending on where's the next waypoint, distance to it and hows the relactive angle between the facing and the next car.
Since the physics are simulated, there's A LOT of randomness in all the races and the times vary constantly. The cars also have different behavior, because of the rear vs. front vs 4wd tractions and different max speeds and accelerations. But if I put one car alone (no fire hits) it's really fast and constant. That's what's expected from a good driver.
An example, AI car laps:
45.573s (first one, froms tart)
43.721s
44.238s
My personal record in this particular track is: 43.271s
This is the hard mode (not final calibration). For medium and easy modes I just add some speed limiter factor to apply against the ideal speed for that sector. This limiter is proportional to the position (1st has the biggest limiter), but this happens only in medium and easy difficulties. In hard mode there are no limits for the AI cars.
Next steps will be:
Make more than one available set of waypoints (different trajectories)
Making the cars get better in long races, learning from mistakes (race strategy also)
Making different CarDriver agents for each car type (parameters or some recordable learning, like neural networks)
I think this is it.