The new adaptive AI

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

  1. mr_belowski

    mr_belowski Well-Known Member Beta tester

    Joined:
    Apr 23, 2015
    Ratings:
    +1,290 / 0 / -0
    Well done sir :)
     
  2. pixeljetstream

    pixeljetstream Well-Known Member Beta tester

    Joined:
    Jan 29, 2015
    Ratings:
    +382 / 0 / -0
    indeed well done,
    so in theory, if we collect lots of xml files from the community (get real difficulty) and build a "lap time per AI level per class per map" database. Then people could prime their settings from that database, much quicker.

    given the amount of people we have on the boards and the activity of their driving we should be able to collect a lot of data rather quickly?

    and if someone is a web-monkey programmer they could automate the whole process on the server database. The more people send in their xml file, the more accurate the online database gets.
    so one would enter the target time they typically want to do (look up their ranking in leaderboards...) and then the generator could spit out a tight packing.

    Actually that is something where s3s could make well use of the "always online" for singleplayer themselves, just data-mine the hell out of this ;)
     
    • Like Like x 4
    • Agree Agree x 1
  3. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    Actually, in order to check that things happen as they should...
    @J-F Chardon can we get the .json file updated , please?
    A lot of the new stuff isn't in there, and thus the only way to find the key-values is to do single laps for each combo.
    Which is something of a pain. :D
     
  4. Not Lifting Off

    Not Lifting Off Well-Known Member

    Joined:
    Dec 5, 2015
    Ratings:
    +348 / 0 / -0
    Maybe not specifically ai but i would hazard a guess that they do\are.
     
  5. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    And just for those who didn't get my vaguely worded explanation of how to do it, here's a vid showing the entire process from start to finish.
    One-take video, with no editing and atrocious sound-quality.....
    But at this point I honestly couldn't be buggered to do anything fancy. :D
     
  6. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    A few final observations on the AI system, and after this I'm going to leave it alone and spend my time doing....you know, actual racing. :D

    First a bit of good news; once you've got a tightly grouped AI index, the adaptation works beautifully.
    I set up FRJ @ Nürburgring, and made an index running through 107 - 112, which I knew was a little too high for me.
    Then I did a 30 min race (and had my ass handed to me) and afterwards the index ran 106 - 111.
    So once you have a good index, it'll slowly adjust up and down based on your current level.
    Although this obviously also means that you have to be fairly precise when setting the initial level.

    The longer race showed something else. The integer attached to each AI level isn't as simple as the number of laps it used that particular level. Adding them together after the FRJ race, I still only had 7 in total.
    It is however some kind of weighting of each level, and in some way controls whether the AI should adjust up or down.
    After the FRJ race I had a 2 in level 107, and a 1 in everything else. And then it shifted the levels down.
    So the assumption on my part is:
    The AI, during the race, compares your lap-times to each level in its index, and then assigns a value to each level.
    If there's a high value in either of the two lower AI levels, it shifts down a notch for the next race. Vice-versa for the two top levels.

    Then there are the lap-times themselves. They are most definitely used in some way by the AI, I'm just not entirely sure how.
    My initial idea was that if it compares its lap-times to yours, then the important thing would be for the lap-times to be fairly equal, but whether they are slow or fast shouldn't make a difference.
    Hmmmm.....
    So I thought, if that's true, then you should be able to use the indexes of one car/class combo in another car/class combo.
    Or in other words, I should be able to copy over my FRJ/Nürburgring index over to NSU/Brands Hacth.
    Obviously the lap-times will differ wildly, but if the AI thinks that both myself and the AI are running at the same speeds, then it should simply use the AI levels in the index, right?
    Well....no. ;)
    What I got was an AI that looked like it started from scratch (i.e. 80%). So the lap-times are used for something.
    Not entirely sure what or how, but you can't do without them.
    I even tried deleting the lap-times themselves, and just leave the AI levels for each index.
    Same result. :rolleyes:
    You can however, copy over your index from GTR3s to the ADACs, and that'll work beautifully.
    So in theory, you should be able to copy over an index if the lap-times are fairly equal.
    Maybe something like DTM'92s to Touring Classics.
    And (again, in theory) it should be possible to manually insert both lap-times and AI levels assuming you have a rough idea of each. But I would be very careful with using that technique.
     
    • Like Like x 1
  7. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    STOP THE PRESS!
    (I always wanted to say that.)
    My initial post was correct, you can train the AI in 6 laps.

    Gawd.....
    Okay, it's official. I really AM a f*cking moron.
    Cletus the Slack-jawed Yokel, that's me. :D

    You can get by with doing 6 laps, not 12.
    The thing that threw me was that earlier I had been using the adaptive AI to get my initial settings.
    And the adaptive AI needs two laps, so it has something to compare to, and thus figure out if it should speed up or down.
    Which means it'll take two laps before it'll write a new index.
    However, being a little slow on the uptake, I failed to consider that we're doing the initial races with FIXED AI levels.
    And since fixed AI doesn't need to adapt (well, duh) it only needs one lap to write an index. *facepalm*

    So, the technique is the same as before.
    Find your AI level for the car/track combo.
    Then do one lap with fixed AI, rolling start, no qualifying, and one opponent at that level and one more each at level -2, -1, +1, +2, +3.
    Your lap-times don't matter*, but it is important that both you and the AI cross the finish-line.
    And that's it, six laps and you're done.
    So even something like the Nords should only take you about an hour.

    Proof of concept:
    Training Aquilas at Monza Jr in 11 minutes.


    *Probably don't matter. Maybe. I think. well.....
    But just in case, don't slack off too much.
     
    • Like Like x 3
  8. jimortality

    jimortality Active Member

    Joined:
    Jun 11, 2015
    Ratings:
    +39 / 0 / -0
    Where can I find the numbers for the cars and tracks? When I go to my AI file, I have to scroll for ages to find what I think is my 6 lap times. Cheers
     
    • Agree Agree x 1
  9. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    • Love it! Love it! x 1
    • Useful Useful x 1
  10. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    Okay, first I really should apologize for getting this information to you all in fits and spurt.
    I really am sorry, it's an unfortunate side-effect of how my brain works.
    (Although 'works' is probably a little misleading. :D )
    I get an idea, test it until I'm happy I'm right, then post the results.......
    A few hours later, I start thinking through the ramifications, get another idea and so on.

    But as it turns out, if you're SURE about your AI level and you're doing consistent lap-times, you can train the AI in one lap.
    And if you have already been doing several races with the same fixed AI level, you can switch to adaptive right away.

    Here's the logic behind it:
    When you start with an empty aiadaptation.xml, and start doing races with the adaptive AI right away, the AI will start at 80%.
    It'll then incrementally ramp up the levels, adding a new index to the file after each race.
    It will do so until there are 6 indexes for that car/track combo, and after that it'll start to delete the extreme indexes, writing new ones that are closer to your level.
    So after enough races, it'll end up with a tight group of indexes, same as the ones I've 'designed'.
    The problem is that you will have to do a LOT of races to get to that point, none of which are likely to be much fun.

    On the other hand, I knew from my FRJ testing that once you have the index in place, the adaptation works beautifully, since it simply scooted the entire index from 107-112 to 106-111.

    Huh.....
    So the problem isn't the adaptation as such, it's that it starts in the wrong place (unless you happen to be at level 80 in the first place).
    So what if we could force the AI to start at the proper place to begin with?
    Well, since a fixed AI will write an index, we can do so by doing one lap under race-conditions.
    Which I promptly tried.
    I deleted the XML-file to start from scratch. I knew from earlier testing that my AI level with NSUs at Brands was 117.
    So I ran one lap with one AI opponent at AI 117, which got me this index:

    <custom>
    <custom>
    <!-- Index:0 -->
    <custom type="float32">63.57659531</custom>
    </custom>
    <custom>
    <!-- Index:0 -->
    <key type="uint32">117</key>
    <custom>
    <custom type="float32">62.74180984</custom>
    <custom type="uint32">1</custom>
    </custom>
    </custom>
    </custom>

    Okay, nothing surprising there.
    So I did a short 8 minute race with adaptive AI, and got this index:

    <custom>
    <custom>
    <!-- Index:0 -->
    <custom type="float32">62.58428574</custom>
    <!-- Index:1 -->
    <custom type="float32">59.51705170</custom>
    <!-- Index:2 -->
    <custom type="float32">59.36094666</custom>
    <!-- Index:3 -->
    <custom type="float32">59.72669983</custom>
    <!-- Index:4 -->
    <custom type="float32">59.79594421</custom>
    <!-- Index:5 -->
    <custom type="float32">59.68527222</custom>
    <!-- Index:6 -->
    <custom type="float32">59.32263184</custom>
    <!-- Index:7 -->
    <custom type="float32">59.93743896</custom>
    <!-- Index:8 -->
    <custom type="float32">63.57659531</custom>
    </custom>
    <custom>
    <!-- Index:0 -->
    <key type="uint32">117</key>
    <custom>
    <custom type="float32">62.74180984</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:1 -->
    <key type="uint32">118</key>
    <custom>
    <custom type="float32">60.03076172</custom>
    <custom type="uint32">1</custom>
    </custom>
    </custom>
    </custom>

    I was apparently a little faster, so the AI decided to shove a 118 in there to deal with me.
    Then (and this is where it gets interesting) I did one more 8 minute race against adaptive AI, and got this index:

    <custom>
    <custom>
    <!-- Index:0 -->
    <custom type="float32">61.38822174</custom>
    <!-- Index:1 -->
    <custom type="float32">59.84841919</custom>
    <!-- Index:2 -->
    <custom type="float32">59.82336426</custom>
    <!-- Index:3 -->
    <custom type="float32">59.56095886</custom>
    <!-- Index:4 -->
    <custom type="float32">61.40167236</custom>
    <!-- Index:5 -->
    <custom type="float32">60.23480225</custom>
    <!-- Index:6 -->
    <custom type="float32">59.18048096</custom>
    <!-- Index:7 -->
    <custom type="float32">59.95336914</custom>
    <!-- Index:8 -->
    <custom type="float32">62.58428574</custom>
    <!-- Index:9 -->
    <custom type="float32">59.51705170</custom>
    </custom>
    <custom>
    <!-- Index:0 -->
    <key type="uint32">117</key>
    <custom>
    <custom type="float32">62.74180984</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:1 -->
    <key type="uint32">118</key>
    <custom>
    <custom type="float32">59.91971588</custom>
    <custom type="uint32">2</custom>
    </custom>
    </custom>
    </custom>

    No new index written.
    Why?
    Well, take a look at the lap-times in the AI indexes. Between race 1 and Race 2, the lap-times for level 117 is exactly the same.
    I mean, identical down to the last decimal.
    So apparently the AI never used it, it only ran at 118% the entire race. And since I wasn't faster than the AI, and it didn't need the next lower AI index either, it didn't bother adding a new index.
    It is now fully trained. :)

    So if you can manage to start the index in the right spot before racing the adaptive AI, there will be a very small adjustment period.
    [​IMG]

    There is however one very large caveat to this method.
    You really have to be sure that the initial level is correct.
    It's OK to be off by one or two levels, but if the difference is too big, the AI will start to jump several levels each race, and you end up back at square one.

    And now I'm really done with the adaptive AI.
    And yes, I mean it this time. I can't train it in less than one lap. :D
     
    • Useful Useful x 1
  11. jimortality

    jimortality Active Member

    Joined:
    Jun 11, 2015
    Ratings:
    +39 / 0 / -0
    Ok how do you know which lap is the AI and which is yours.
     
  12. jimortality

    jimortality Active Member

    Joined:
    Jun 11, 2015
    Ratings:
    +39 / 0 / -0
    Thanks for doing this it's very much appreciated.
     
  13. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    <custom>
    <custom>
    <!-- Index:0 -->
    <custom type="float32">62.58428574</custom>
    <!-- Index:1 -->
    <custom type="float32">59.51705170</custom>
    <!-- Index:2 -->
    <custom type="float32">59.36094666</custom>
    <!-- Index:3 -->
    <custom type="float32">59.72669983</custom>
    <!-- Index:4 -->
    <custom type="float32">59.79594421</custom>
    <!-- Index:5 -->
    <custom type="float32">59.68527222</custom>
    <!-- Index:6 -->
    <custom type="float32">59.32263184</custom>
    <!-- Index:7 -->
    <custom type="float32">59.93743896</custom>
    <!-- Index:8 -->
    <custom type="float32">63.57659531</custom>
    </custom>

    <custom>
    <!-- Index:0 -->
    <key type="uint32">117</key>
    <custom>
    <custom type="float32">62.74180984</custom>
    <custom type="uint32">1</custom>
    </custom>
    <!-- Index:1 -->
    <key type="uint32">118</key>
    <custom>
    <custom type="float32">60.03076172</custom>
    <custom type="uint32">1</custom>
    </custom>

    </custom>
    </custom>

    Anything in red is my lap-times, the green bits are the AI times and levels.
    How do I know this?
    Two ways, first of all, if you run races without AI opponents (races, not practice or leaderboard) it'll write a lap-time.
    Second, an AI index will also list an AI level in the same index.
     
    • Like Like x 1
  14. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    No need to thank me.
    I'm doing this for myself, to get good AI racing.
    I just happen to be sharing the results. :D
     
    • Like Like x 1
  15. kamackeris

    kamackeris Active Member

    Joined:
    Dec 12, 2015
    Ratings:
    +25 / 0 / -0
    I think you have found what I have been kind of getting at with my earlier posts in that it was a pain to build up the ai to that level you are at when you kind of roughly know already what level you are at so why not be able to start from where you know you are at and let it adapt from that... And you have proved it!

    So if I already have been doing laps at a certain level then all I do is switch to adaptive and it will just start adapting around my level I was already running at Yeh ?

    Now let's just hope that they improve the overall ai with the next patch.... Then I will be happy!
     
  16. Christian Göpfert

    Christian Göpfert Topological Agitator Beta tester

    Joined:
    Apr 8, 2015
    Ratings:
    +2,243 / 0 / -0
    Yep, as long as you've been doing more or less constistent laptimes, without too much variation between the laps that is. This is the key to all this, if you spin out every other lap it will have a harder time getting up to speed.
     
    • Like Like x 1
  17. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    Yep, the problem isn't that adaptation algorithm as such.
    The reason it takes so long to get it to your own level is that it starts at the wrong place.
    Come to think of it, considering that the AI index runs from 80 to 120, it would be far better if it started in the middle (i.e. 100) instead of starting at 80.
    Although the down-side to that is that if you're running below 100 to begin with, you'll have quite a few races where you'll have your ass handed to you before it starts to adapt.
    Which I suppose might discourage people from racing it in the first place.
     
  18. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +336 / 0 / -0
    Actually, if you've been running fixed AI, the lap-times don't matter as long as the AI level is correct.
    Long as you run the same AI it won't write any new indexes.
    So if you've been running at 105 and that is actually your level, you can switch to adaptive right away.
    The lap-times only comes into play once you run adaptive, and even then you can get away with 1-2 spins in a race.
    Since the indexes are weighted it won't bother writing a new one as long as the majority of your laps are kept within the existing index.
     
    • Informative Informative x 1
  19. jimortality

    jimortality Active Member

    Joined:
    Jun 11, 2015
    Ratings:
    +39 / 0 / -0
    I.I'm not consistent enough :(
     
  20. digitizer

    digitizer Well-Known Member

    Joined:
    Mar 26, 2016
    Ratings:
    +117 / 0 / -0
    I think it will be good to know some avr. lap times for different AI lvl. It can help to find right AI lvl faster. I just look my adaptive ai file and find for different track/car ai lvl can be so different, from 97 to 107