supertuxkart / stk-code

The code base of supertuxkart
Other
4.46k stars 1.05k forks source link

Further racing AI refinements #3147

Open Alayan-stk-2 opened 6 years ago

Alayan-stk-2 commented 6 years ago

This is a list of the main areas where the AI could use significant improvements with thoughts on each. Consider this as a sort of progress-tracking list.

To identify issues, I highly recommend launching a race and set the camera to one of the AI kart. This allows to much better see how the AI acts.

There may be others. Write a comment if you think of one.

Alayan-stk-2 commented 6 years ago

Seen looking at AI races : the AI sometimes insists on keeping skidding so much, while it already could get the bonus and there is a straight line ahead, that it goes off-track. E.g. ; at the last curve in XR591 ; I got an AI falling to the left and having to go do the curve again... twice in a row !!!

Alayan-stk-2 commented 6 years ago

For (6) ; here is a helpful image to better understand the issue :

itemsai

Black is how AI seems to evaluate things ; blue is how it may drive. (Not exact values ; it's only the general idea)

This means that : (a) it will miss some items it thought it could catch (those who fall between the blue and black line) ; (b) if the item is a bit further and can be catched (beyond the black/blue crossing but close to the black line) it will arrive at it with a much worse direction than expected, throwing it out of track.

Alayan-stk-2 commented 6 years ago

The new pathing algorithm was supposed to look ahead at left and right points until the line they trace join. However, it is bugged.

        // Test if the next left point is to the right of the left
        // line. If so, a new left line is defined.

If the next left point was instead to the left of the current left line (or the right to the right of the current right line), then we would break out of the loop, which defeats the whole point of trying to get the left and right line to join.

Then, the other issue is that it's the center of the last node in the loop which is used, rather than the appropriate left/right point matching the joining lines.

With that fixed, the pathing algorithm should work much better.

Then, it is a matter of making skidding work nicely.

EDIT : With those fixes applied, the pathing is finally good ! A tux completed 3 time-trial lighthouse laps in 1:30.04 without skidding at all. For comparison purposes, I got 1:23.48 in those conditions (7% less) but that is getting some nitros the AI didn't and better managing it/zippers. If I miss the double nitro at one place in the path like the AI (which points to a weakness in the item collection algorithm), I lose 3-4 seconds. The previous AI steer more to the center and get those cans, but (without skidding) only beat the new time by 1,5 seconds ; so there is around 2 seconds in pathing difference.