The new adaptive AI

Discussion in 'General Discussion' started by Paradox Agi, Apr 18, 2016.

  1. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    That's excellent news. :)
    Time to go a-testing methinks. :D
     
    • Like Like x 1
    • Useful Useful x 1
  2. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,287 / 0 / -0
    I've never actually used it, but my adaptation.xml (or whatever it's called) is full of data so I guess it must collect data even when you're using fixed AI
     
    • Agree Agree x 1
    • Informative Informative x 1
  3. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    Yep, confirmed.
    Just did a fixed AI race, and the aiadaptation.xml sucks in the data like it's nobodys business.
     
    • Funny Funny x 1
  4. kamackeris

    kamackeris Active Member

    Joined:
    Dec 12, 2015
    Ratings:
    +25 / 0 / -0
    Where is the ai adaption file I couldn't find it just?

    Also just had a quick go on monza and the corner after the 2nd Chicane the ai seemed to be having trouble with it with gt3 saw 3 spins in about 8 laps anyone else seen this?
     
  5. digitizer

    digitizer Well-Known Member

    Joined:
    Mar 26, 2016
    Ratings:
    +117 / 0 / -0
    ...\SimBin\RaceRoom Racing Experience\UserData\Player1
     
  6. Tobias Schröder

    Tobias Schröder Well-Known Member

    Joined:
    Jan 29, 2015
    Ratings:
    +270 / 0 / -0
    ...and what I mixed up is that the ai adaption file is in your documents, not in your game folder, maybe you made the same mistake.
     
    • Like Like x 1
  7. James Cook

    James Cook Well-Known Member

    Joined:
    Jan 30, 2015
    Ratings:
    +1,008 / 0 / -0
    Don't bother with adaptive AI. Just find a baseline AI difficulty level and work with that. You'll know which tracks you are a little quicker at so you can bump it up a couple of notches and vice versa for tracks you are not so comfortable with.
     
    • Disagree Disagree x 2
  8. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    Don't be so quick to judge. :D
    After testing it most of last night, I figured out that you can actually train it by doing six laps, assuming that you're willing to do some manual editing of the XML.
     
  9. kamackeris

    kamackeris Active Member

    Joined:
    Dec 12, 2015
    Ratings:
    +25 / 0 / -0
    do tell......
     
  10. kamackeris

    kamackeris Active Member

    Joined:
    Dec 12, 2015
    Ratings:
    +25 / 0 / -0
    the only folder i have in documents, simbin is race07 ??
     
  11. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,287 / 0 / -0
    could do with a tool to generate the adaptive AI xml file, maybe take some lap time / track / car class combo as input data and then it'd add the appropriate bits to the XML file to give you AI adapted to the laptime you specify

    If only there were developers floating around here
     
  12. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    Oh, don't worry, I'm not just going to leave it hanging there. :D
    But it's a little hard to explain without showing it, so I'm planning to put together a short video on it some time this week-end.
    If that for whatever reasons fails, I'll see if I can't hack together a forum-post instead.
    I just think it'll be easier to explain through a video.
     
    • Like Like x 1
  13. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    it's documents/my games/SimBin......
     
  14. digitizer

    digitizer Well-Known Member

    Joined:
    Mar 26, 2016
    Ratings:
    +117 / 0 / -0
    Adaptive AI kidding me. Just start 30 min race with Bentley at Nordschleife. Default setup (50l of fuel). 1km to finish line i'm stopped because fuel empty. I'm drink a cup of coffee and start race again with 2l fuel more. But AI in previous race take a lot of driving skills i think and i need to race harder... 2km to finish line - fuel empty ... :D Only in 3rd race with 59 liters of fuel, i'm finished :D
     
  15. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    Should in theory be possible.
    The AI uses six iterations to adapt to you, starting 90% and if he hasn't caught you by the 5th iteration, it jumps to 120%.
    So if you could add those six iterations beforehand, that would solve it.
    The stumbling-block right now is that each iteration state both the percentage-level and a lap-time.
    So without knowing which lap-time each AI percentage approximately equals, I suspect it might upset the AI adaptation severely.
    I suppose you could simply run races with fixed AI, and watch what lap-times it results in, but if you're going to need to do laps anyway, it's easier to simply edit the XML after each run, and let the AI do its thing on its own.
     
  16. Not Lifting Off

    Not Lifting Off Well-Known Member

    Joined:
    Dec 5, 2015
    Ratings:
    +347 / 0 / -0
    Sure i hinted at this earlier in the thread ;)
     
  17. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    Damn it, I told a lie....
    Found something else out about how the AI works, so it's 12 laps, not 6......*sigh*
    Bloody computers. :D
     
  18. Christian Göpfert

    Christian Göpfert Topological Agitator Beta tester

    Joined:
    Apr 8, 2015
    Ratings:
    +2,227 / 0 / -0
    Have you found out if/had an instance where they can go beyond that? That the laptime they use can be even faster than the one being used at 120?
     
  19. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    So far I've only seen 120.
    I don't think it can go beyond, but that's just a hunch.
    My problem is that I can't challenge 120% AI consistently enough for the adaptive AI to see the need to increase it.
    Just a problem of my skill-level. :D
     
  20. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +334 / 0 / -0
    A little disclaimer: I agree with a lot of what's being said on other threads.
    The AI in its present condition is a little sterile, and usually doesn't fight other AI racers much.
    There's also the collision-problem, and the magical brakes at the end of a brake-zone.
    That said, I have full faith and confidence that these issues will be fixed. Considering the leaps of improvement we've seen in other areas of this sim, it would seriously surprise me if we didn't see AI improvement as well.
    All that however, is not the point of this thread, which is about the adaptive AI specifically.
    So we now return to our regularly scheduled broadcast, which revolves around getting the adaptive AI up to player-speed quicker.

    To start with, I will say that there won't be a video on how to use XML editing to get faster adaptive AI.
    Why not?
    Because I'm a f*cking moron, that's why. :D
    I spent 2 hours testing some ideas, then a further 4 hours getting game-footage, doing narration explaining all this stuff, editing and so on.
    Then after I was happy with the final edit, I decided to test out a few other things mentioned earlier in the thread to see if I could answer everything at once.
    Bad news: The video was outdated before I had even rendered it...... *sigh*
    Good news: I figured out a way to get a fully trained adaptive AI in 12 laps, without having to edit anything.
    All you have to do is 12 laps without ever leaving R3E.

    Technical section and a wall of text ahead.
    If you have no interest in what I did or why it works, scroll down until you see another dotted line to find out HOW to do it.
    -----------------------------------------------------------------------------------------------------------------------------------

    The first thing I decided to test was whether you were better off training the AI without actually having AI on the track.
    You're definitely not. In fact, you CAN'T train the AI without having AI on track.
    I'll tell you why in a moment.

    The second thing I wanted to test was whether you can train the AI using races against fixed AI.
    Again, no you can't. Or rather, not directly.
    But you can most certainly use fixed AI in another way to get the result you want.

    As it turns out the lap-times in the XML are utterly useless to the initial training of the AI, they only come into play AFTER the AI is trained. What you should be looking for is the AI indexes just below them.
    How it works......... correction, how I think it works is that the adaptive AI writes an index after each race.
    The number of indexes vary a bit (not sure why) but the average seems to be six indexes for each car/track combo.
    DURING the race the AI then uses these indexes to vary it's lap-times. If you start to fall behind, it goes to the next lowest index for the next lap. If you still fall behind, it steps down again and so on.
    Obviously vice-versa if you're faster than the AI.
    If you're still too fast after the AI uses its fastest index, it'll write a new one after the race, upping the ante the next time you race that combo. If the maximum number of indexes are already used, it'll delete the least used one.
    Short version, if you outran the AI, after the race it'll delete the slowest index, and write a new index with a higher AI level than the current highest.
    Fairly simple algorithm, no surprises there.

    Okay, but the problem still remains. Since the AI start at 80% by default, It'll take a lot of races to get competitive, especially considering that the closer it gets to your lap-times, the smaller increments it'll increase by.
    So my initial idea was that if you 'hacked' the XML and fooled the AI into thinking you were actually much faster, it would increase its speed in larger increments.
    What I did was take my personal best for a combo, subtract a second from that, and enter that manually into the XML.
    First hurdle I ran in to was making the mistake that one lap was enough to count as a race.
    I mean, it's enough to get a lap-time into the XML so that should train the AI as well, right?
    Nope, doesn't work like that. As I said, the lap-times are useless in training the AI.
    What happens is that the AI compares your last lap-time to its last AI level, and if that isn't fast enough it tries a higher level next lap.
    But the kicker is that it can't know whether it was successful until after the lap is finished.
    And it won't discard its base-line until it has a new one to try.
    Pure Boolean logic:
    After Lap 1 it asks "I tried at 80%, was that enough?"
    After Lap 2 it asks "I tried at 90%, was that enough?"
    But unless it knows that the next level failed as well, it won't abandon the first one.
    So you need to do two laps per session, otherwise you won't get anywhere.

    It also explains why you can't train the AI without having AI on track.
    Without AI, no comparisons are made, and thus no new indexes are written.

    Alrighty then.
    So I started doing two lap races, then edited the XML manually, and watched what happened to the AI indexes.
    This is an example from my old XML file, showing Aquilas at Brands Hatch.

    <custom>
    <custom>
    <!-- Index:0 -->
    <custom type="float32">48.78387451</custom>
    <!-- Index:1 -->
    <custom type="float32">48.79570007</custom>
    <!-- Index:2 -->
    <custom type="float32">48.69625854</custom>
    <!-- Index:3 -->
    <custom type="float32">49.31530762</custom>
    <!-- Index:4 -->
    <custom type="float32">48.94433594</custom>
    <!-- Index:5 -->
    <custom type="float32">48.60922241</custom>
    <!-- Index:6 -->
    <custom type="float32">49.06225586</custom>
    <!-- Index:7 -->
    <custom type="float32">49.31475830</custom>
    <!-- Index:8 -->
    <custom type="float32">49.27456665</custom>
    <!-- Index:9 -->
    <custom type="float32">48.91101074</custom>
    </custom>
    <custom>
    <!-- Index:0 -->
    <key type="uint32">90</key>
    <custom>
    <custom type="float32">57.20594025</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:1 -->
    <key type="uint32">106</key>
    <custom>
    <custom type="float32">51.62752914</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:2 -->
    <key type="uint32">109</key>
    <custom>
    <custom type="float32">51.53813934</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:3 -->
    <key type="uint32">111</key>
    <custom>
    <custom type="float32">51.20059204</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:4 -->
    <key type="uint32">112</key>
    <custom>
    <custom type="float32">51.15437317</custom>
    <custom type="uint32">2</custom>
    </custom>
    <!-- Index:5 -->
    <key type="uint32">114</key>
    <custom>
    <custom type="float32">50.68688202</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:6 -->
    <key type="uint32">120</key>
    <custom>
    <custom type="float32">49.31999588</custom>
    <custom type="uint32">2</custom>
    </custom>
    </custom>
    </custom>

    This one is after 8 two-lap races if memory serves, and I've only edited the first 6 of those, so we're already seeing some adjusting.
    The Index goes 90 - 106 - 109 - 111 - 112 - 114 - 120.
    By this point I was extremely pleased with myself. :D
    I had after all gotten the AI up to speed in very few laps.
    Only....
    When I subsequently tried racing it, it behaved oddly with wild variations in lap-times.
    In hindsight it's pretty obvious why, since there are some large gaps between the indexes.
    So if you fall behind the AI goes to the next lower index, and if that index is 10-12 percent lower....Well....

    Okay, so by now I'd figured out that a good adaptive AI has tightly grouped indexes, making it possible for it to make small adjustments in tempo, both up and down.
    But I couldn't figure out how to make it do that AND get up to speed quicker. As far as I could see you had to do race after race after bloody race to get the tight groupings.
    So I thought I'd do a video showing how to at least get it up to speed quickly, and make the caveat that it would still need further races in order to become good at varying speeds.

    After doing the video, as mentioned earlier, I decided to test AI training both without AI and with fixed AI.
    Obviously, without AI, no indexes, and thus no training. Scratch that idea.
    The fixed AI does however write an index. It's a fixed index obviously, but it does get written.
    And this is the Heureka moment.
    Also know as the "Why the f*ck didn't I think of that earlier?!" moment. :confused:

    If you...
    • know your approximate AI level
    • know that good adaptive AI needs tight groupings
    • know how to get a specific AI index written
    wouldn't it be possible to 'design' a tightly grouped index for the AI to follow?

    I knew my AI level with NSUs at Brands was about 115% (give or take).
    So I did two laps each at 113, 114, 115, 116, 117, and 118, with one AI opponent to write the index.
    Which resulted in this index:

    <custom>
    <!-- Index:0 -->
    <key type="uint32">113</key>
    <custom>
    <custom type="float32">61.74826813</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:1 -->
    <key type="uint32">114</key>
    <custom>
    <custom type="float32">61.53697968</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:2 -->
    <key type="uint32">115</key>
    <custom>
    <custom type="float32">61.08876038</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:3 -->
    <key type="uint32">116</key>
    <custom>
    <custom type="float32">60.94928741</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:4 -->
    <key type="uint32">117</key>
    <custom>
    <custom type="float32">60.79580688</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:5 -->
    <key type="uint32">118</key>
    <custom>
    <custom type="float32">60.15036011</custom>
    <custom type="uint32">1</custom>
    </custom>
    </custom>
    A nice tightly grouped index, with about 1,5 seconds spread.
    Purrrrfect. ;)
    Then I did a full 8 minute race with 10 opponents and got a very serious fight (see video at end of post).
    Even better, I re-checked the index after the race, and got this:
    <custom>
    <!-- Index:0 -->
    <key type="uint32">113</key>
    <custom>
    <custom type="float32">61.74826813</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:1 -->
    <key type="uint32">114</key>
    <custom>
    <custom type="float32">61.53697968</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:2 -->
    <key type="uint32">115</key>
    <custom>
    <custom type="float32">61.08876038</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:3 -->
    <key type="uint32">116</key>
    <custom>
    <custom type="float32">60.79580688</custom>
    <custom type="uint32">2</custom>
    </custom>
    <!-- Index:4 -->
    <key type="uint32">117</key>
    <custom>
    <custom type="float32">60.58061218</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:5 -->
    <key type="uint32">118</key>
    <custom>
    <custom type="float32">60.15036011</custom>
    <custom type="uint32">1</custom>
    </custom>
    </custom>
    Note that when compared to the 'artificial' one, the AI indexes are exactly the same.
    There are some small variations in the lap-times of level 115 and 116, but apart from that the adaptive AI didn't feel the need to change anything.

    One more thing to mull over, and that needs further testing.
    Below the lap-times, there's an integer key.
    The sequence is 1, 1, 1, 2, 1, 1.
    Now, this is admittedly a very small sample-base, and one should be careful drawing conclusions on such a small data-set.
    But I think it's the number of laps the AI used that particular level, in order to weigh each level.
    So if it needs to change a level to adapt, it'll change the one that got used the least.
    Furthermore, there are only seven laps, even though I did eight laps.
    Which leads me to believe the AI only used the seven fastest laps, discarding the start lap.
    So why did I complain earlier in the thread that the start-laps were dragging the average lap-times down?
    Again, careful with the conclusions, but I would suggest that it only starts discarding laps once it has enough new laps to fill the entire index.
    Earlier I only did two-lap races, and since that wasn't enough for each index to get a comparison, the AI never discarded any of them.

    EDIT: Scratch that. Poor logic on my part.
    The reason it only shows 7 integers, is the same reason you need two laps to write a new index.
    It's not the number of laps, it's the number of comparisons.
    The AI only does comparisons after each lap, and only does so if there's a new lap ahead to adapt to.
    And since the last lap obviously doesn't have a lap following it, there's no comparison made.
    This also explains why the start-laps in two-lap adaptive races never increased the AI speed.
    Since I stopped after the first flying lap, there was no lap after that, and thus the flying lap never got a comparison, meaning I've been trying to teach the AI based on starting laps. *sigh*
    I swear, one of these days I'm going to actually use my noggin before jumping to conclusions. :D

    Anyway....
    Job done, that's how you can browbeat the AI to your level very quickly.
    (And now I'm going to sleep for a friggin' fortnight....)
    ----------------------------------------------------------------------------------------------------------------------------------------

    So to recap for those who didn't want to follow the geek-speak:

    Two major rules to remember:
    1. The more consistent your lap-times are, the more fun you will have.
    2. The better your initial level-assessment is, the quicker you'll get good racing.

    Step 1.
    So, you first need to establish your approximate AI level at a given car/track combo.
    If you're already fighting fixed-percentage AI you already have a good idea of where you're at.
    If not, you need a little patience to do some qualifying sessions.
    Use races against 8 AI opponents, select an fixed-percentage AI level, and use qualifying. Never actually enter the track yourself, just take note of the lap-times the AI does. And let them run at least 2 laps, preferably 3.
    Keep changing the AI level and keep doing this until your best time would've placed you around 3rd or 4th.

    Step 2.
    The way adaptive AI works is that it needs to be able to slightly vary its speed in the race.
    In order to build up the AI database, we need to run a series of two-lap races (6 of them to be exact).
    Each of these are to be run with only 1 AI opponent, and without qualifying. Just place yourself in first, and off you go.
    What you do is run two laps at your AI level from step 1.
    The you need to run two more laps each at level -2, -1, +1, +2 and +3.

    Example: Let's say your AI level is 112%.
    The you need to run two laps each at AI 110, 111, 112, 113, 114, and 115.
    And that's it, you're done.
    You now have a fully-trained adaptive AI for that car/track combo.
    You're welcome. :)

    And just to illustrate it.....
    I deleted my aiadaptation.xml file so I could start fresh.
    I knew my AI level was about 115, so I ran two laps with one AI opponent at level 113, 114, 115, 116, 117 and 118.
    That's the ONLY thing I did. I never edited anything, nor did any other technical magic.
    Then I did a 'real' race with adaptive AI and I got this:


    Now, if you're sitting there thinking "Pfft. 60 seconds a lap? You call that a fast AI, mate?"...
    Then you're completely missing the point.
    The object of the exercise is to get an AI that is adapted to YOUR level, not necessarily a FAST level.
    If you want a fast AI, crank it up to 120% and have at it.
    But the point is that even though the race may look slow to some of you, and many of you could probably beat my lap-times blindfolded........
    In order to keep up with the top three guys, I'm driving my tits off.
     
    • Like Like x 8
    • Informative Informative x 4
    • Winner Winner x 1
    Last edited: Apr 30, 2016