Why I won't be doing an adaptive-AI championship...

Discussion in 'General Discussion' started by Skidmark, Sep 22, 2018.

  1. J-F Chardon

    J-F Chardon KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +5,041 / 0 / -0
    Damn, pressure is on for us not to break it, now. You sure we should touch it? :p
     
    • Agree Agree x 1
    • Funny Funny x 1
  2. Fleskebacon

    Fleskebacon Well-Known Member

    Joined:
    Feb 16, 2015
    Ratings:
    +258 / 0 / -0
    Please don't break anything. :(
     
  3. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    LOL, absolutely. :D
    As brilliant as the system is, there are some issues with bad laps interfering with the process.
    And while there are several ways to implement a solution, I don't have a clue as to which would be the easiest to code.
    I leave that to the guys who actually know what they're talking about.

    Although.....
    Having said that, if the new system somehow resets my index-file, I might get a little miffed. ;)
     
  4. J-F Chardon

    J-F Chardon KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +5,041 / 0 / -0
    Better back it up :p
     
  5. J-F Chardon

    J-F Chardon KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +5,041 / 0 / -0
    How would you like getting on the other side of the fence and test this in beta ?
     
    • Like Like x 2
  6. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    Depends on what you require.
    The main reason I haven't applied is that my time is limited. I work odd (and long) hours, so I really only get behind the wheel on week-ends.
    Now, if you can live with that, by all means point me in the right direction, and I'll be happy to give it a whack.
     
    • Winner Winner x 1
  7. MattStone

    MattStone Well-Known Member

    Joined:
    Mar 6, 2016
    Ratings:
    +169 / 0 / -0
    Thanks for that explanation...it actually makes sense lol

    So ultimately it looks like it’s the slow laps caused by incidents that can really throw the system out.
    Isn’t there a simple statistical function/calculation that can dismiss laps that are outside a specified tolerance so that those laps are not used to calculate the average?
     
  8. Skidmark

    Skidmark Well-Known Member

    Joined:
    Oct 9, 2015
    Ratings:
    +232 / 0 / -0
    Thanks J-F - one of the things I really love about this forum is the direct involvement you guys have with us. I understand you can't always fix things (or at least not quickly!) but your responsiveness on little issues like this is really appreciated.

    My 2c worth:

    The guiding principle for a single adaptive-AI should be that it is possible, but challenging, for the player to win a race when they are driving at or near their best.

    To do this the adaptive-AI needs to work out what the player is capable of and run at that level. This shouldn't mean getting the player's fastest ever lap and having the AI do that for lap after lap, but rather be an average of (say) the players best 10 laps in the last 20-30, keeping in mind the bottom 10-20 laps will be full of mistakes, laps in traffic etc.

    MattStone has a similar idea above (his option 3) as have others.

    I realise you guys will have thought a lot about this and it's never as simple as it looks from our side of the fence, but I think the principle is what most of us are aiming for.

    This sounds great to me but I'd prefer it to be based on best laps rather than a single lap.

    It's hard isn't it? We want it to be challenging (i.e. difficult) and fun (i.e. not so hard to win its dispiriting).

    Thanks again for responding on this!
     
  9. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    Nor will it, assuming I've understood the new system correctly.
    As it is now, the indexed lap-time for an AI level is already the average of the fastests laps the AI has done in a race.
    It doesn't mean the AI will run those lap-times consistently throughout the race.
    It rarely does so, especially when dealing with traffic.
    All that has really changed is that it'll be compared to the players fastest lap instead of the average lap.

    Granted, it might make it harder to advance through the field, but I'll comment on that when I see it in action.
    In the meantime, anything that rewards consistency over the odd fast lap gets my vote.
     
    • Like Like x 1
  10. Skidmark

    Skidmark Well-Known Member

    Joined:
    Oct 9, 2015
    Ratings:
    +232 / 0 / -0
    I realise the adaptive AI is getting some tweaking (thank you J-F!) but I'm still finding the current system a tad odd.

    As my average lap times stay flat or falling the AI struggles to adapt to my pace (currently it's 7 seconds a lap slower).

    Looking at the xml file, I pulled out the Bathurst WTCR entries and compared it to my last race.

    It shows that the xml file contains 9 of the 10 laps of my most recent race (excluding the first lap, quite sensibly) and for the 10th lap the xml file has retained lap 2 of my previous 10-lap race. (xml file always retains 10 laps).

    One answer might be for me to do 12 lap races so that lap 1 (always ignored anyway) and lap 2 (often affected by traffic) are always excluded.

    Posted this for anyone interested in how adaptive currently works....

    upload_2018-9-30_9-57-16.png
     

    Attached Files:

    Last edited: Sep 30, 2018
  11. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    Wrong assumption. While you're basing it on the right facts, you're reaching the wrong conclusion.
    Your problem isn't that your lap-times are affected by traffic, it's that its affected by slow traffic.
    If the AAI was up to speed, the traffic you encountered would be running at roughly the same speed as you do, therefore the effect on your lap-time would be negligible.
    So it's not a case of figuring out how many laps to do in order for the AAI to exclude the trouble-spots, it's a case of getting the AAI up to speed as quickly as possible.

    Which brings us to the algorithm that governs the AAI, and how much it jumps in order to adapt to the player times.
    While it does sorta, kinda work, if you leave it to its own devices it's a little wonky and has two major problems.

    First off, the adaptation process is too slow. The files are encrypted, so I can't tell you how it works right now, but I can tell you how it should work. Start at 100, then jump 10 levels, next jump 5 levels, then 2, 2, and 1.
    It's a process called root-finding by bisection (or bracketing if you're an artillery man), and while there are far more elegant ways to do it, since we're only dealing with 40 possible levels, brute-forcing it is fine.
    But by doing the above, you're guaranteed to never use more than 6 races in order for it to adapt.

    Second problem is linked to the first one. The AAI in its current state uses far too many attempts in the slower levels before it eventually adapts. Not only does this mean it'll take longer, it also means those slow lap-times are retained in the index-file.
    Which isn't a problem for the track in question, but it does have consequences for any following combo.
    If the AAI doesn't have any entries, it'll use the average of all the other entries it has for that car (or track. It tries the cars first).
    I think the initial idea was that if you base any new combo on the average of earlier combos, it should start in roughly the right place. But since we have all those early and slow attempts still stored in the index-file, the average is dragged way down, and we're back to having the AAI slowly moving up in pace.
    Eventually you'll get more fast laps than slow laps in there, and that'll sort out the problem but it'll take ages.

    So those are the problems, how do we go about solving them?
    Well, the algorithm needs re-doing so we don't spend all those races with too slow AI.
    Next, once the player level for any combo is found, the AI should delete any entries more than e.g. 3% off that level in order to retain an accurate average for any future combos.
    Which is all well and good, but we have to wait for S3 to implement those things.

    In the meantime, you can circumvent the process by racing against fixed AI.
    The ideal entry for the AAI contains your actual level, one 3 levels higher, and one 3 levels lower.
    So let's assume that you're starting from scratch with a brand new index-file, and you have no idea what level you're at.
    Okay, so do the bisection-method described above. Start at 100, then halve the difference each time until you reach the desired level. Next, run races against fixed AI at plus and minus 3 levels. That's that combo done.
    At this point you have two options; you can either manually delete the entries that are too slow, or you can simply make a mental note of the AI level that suited your pace.
    Next combo, if you manually deleted the entries, use adaptive for the first race, then use fixed AI using bisection to find the right level. Or alternatively, use the same fixed AI that you ended up using earlier, then adjust from there.
    Rinse and repeat.
    And yes, it'll take time in the beginning. The good news is that once you have a decent sampling rate (say 10-12 combos done), you can switch to adaptive for the rest of your life (or until S3 adjusts the AI :D ).
    When you have an index-file that contains none of the slower AAI attempts, the odds of the AAI hitting the right level the first time is much higher.
    You may have the odd race where you'll have to use fixed AI to adjust the level (especially when switching class) but generally speaking the AAI works much better once it has a solid foundation to stand on.

    So what do you do if you already have an index-file containing those slow AI entries?
    You're sh*t out of luck, and the only solution is to delve into the file yourself and manually delete all those slow entries.
     
  12. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    I can't see how stored AI laptimes for lower skill levels would in any way harm calculations further on. Also, this is the basics of how the adaptation process is done, maybe it helps:

    We can't start AAI off at 100, which could scare away new players:
    - start at 80 when there is no data in file
    - after that you have data for 80, and if player is slower than AI, level will be 80. If player is faster, there's a crude calculation that aims to set level higher than player's time suggests
    - now there is data on both sides of player's skill, which then can be easily interpolated to a close level

    Starting with a car and a track that don't have data for that specific combo:
    - if car data exists on other tracks, get the averaged level from those
    - if only track data exists, get the averaged level from those entries
    - if neither exists, get the averaged level from all combos
    - next time data will exist for this combo

    Collecting player times:
    - stores up to 10 fastest times after session (pushing out old entries in file)
    - recent wip changes makes it remove ones more than 3% slower than the average of the other ones, before storing, to avoid standing start laps, pit laps, accidents etc.

    Collecting AI average times:
    - after session, it takes each AI's fastest laptime and makes an average out of them all
    - removes entries differing more than 3%
    - if data already exists for that combo and level, it adds this average to existing average using a stored weight of how many sessions existing average was based on, and ups that
     
    • Informative Informative x 9
  13. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    Fantastic news.
    That should solve pretty much all issues with the 'wrong' values being stored. One problem solved, but there's still a minor snag.

    Fair point. But if you're going to start at 80, the AAI should jump by 10 levels until it overshoots the target.
    Which brings us to

    Then may I kindly ask you to look again? :)

    Let me get something out of the way immediately.
    The problem I perceive is based two assumptions. These assumptions are based on fairly extensive testing of the AAI, but they remain assumptions.
    So if either of the two are wrong, feel free to ignore everything that follows.

    Assumption 1: I don't know exactly how the 'crude calculation' you refer to works, but based on testing it seems to jump a number of levels based on the time difference between the highest level run so far and the player lap-times.
    In other words, it'll jump a fair number of levels the first time, a bit fewer the next, and then fewer and fewer still as it approaches the target value.

    Assumption 2: When left to its own devices (ie. without using fixed AI or manual editing to help it along) I have never seen the AAI overshoot the target. Ever.
    Doesn't necessarily mean it can't do it, but I assume it's designed to inch closer and closer to the target value without jumping too far and possibly scare off players.

    And it's the lack of overshooting that is the problem.
    Take me for instance. Taking a very rough estimate over all possible combos, I'm about level 105.
    Varies a fair bit from 95 in the fast open-wheelers to 115 in the more manageable cars, but let's call it 105.
    So the premise here is that after e.g. 10 combos the AAI should start any new combo somewhere in the neighbourhood of 103-107, agreed?
    This example is going to use complete made up level-shifts, but I've done enough testing to be fairly confident that they're not entirely off the mark.
    I'm also going to presuppose that I'm consistent enough for variations in player lap-times not to be a factor in this case.
    Okay, so starting a new index-file from scratch, the logical thing to do (to my mind at least) would be to run one combo over and over again until it was up to speed, then switch either track or car.
    So I pick a combo, and start running against the AAI aiming for a value of 105.
    First attempt it runs at 80. Next 90. Then 96, 100, 103. At which point the AAI usually stalls, and starts running 103 over and over again.
    So I switch tracks. This time the AAI starts at 94 (average of the earlier entries). Then it does 98, 101, 104.
    Next track, it'll start at the new average which is 96. Then it does 100, 103, 104.
    So after 13 races the starting point of any new combo is still 'only' 98-99.
    Do you see what I'm getting at? All those starting entries are dragging the average down, meaning the next combo will always start too slow, which again drags the average further down.
    If the AAI never overshoots the target in any single combo, it'll never reach the actual target, which in turn means that the combined average will also never actually reach the target.
    Using averages to reach an intended target-value only works if you have entries on either side of that value.

    In its present state the AAI works beautifully IF you have entries slightly higher and slightly lower than the target value.
    Then it'll happily explore the territory in between without any problems.
    But try as I might, I can't get it to overshoot on its own, I have to manipulate it manually.
    One way to fix it is, as I mentioned earlier, to have the AAI jump a specific number of levels until it overshoots, then start moving down again.
    Combine that with deleting any entries that are off by more than e.g. 10 levels, and you should be able to get the AAI in the right ballpark with a minimum number of races needed.
    Using the above example, the AAI would run 80, 90, 100, 110. Then it would delete the 80 and 90 entries since they're more than 10 levels off. Now the AAI can explore the territory between 100 and 110, and the average after 4 races is 105.

    Finally, let me be absolutely clear.
    I'm not nit-picking, or trying to invent a problem here. I am a huge fan of the AAI system, especially after I figured out how to manipulate it.
    I just wish it was a little more efficient.
     
  14. Robert Holm

    Robert Holm KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +162 / 0 / -0
    Still dont think I can repro what you say. Did this today, is there anything in there that is what you experience?
    Btw we start AAI at 85 nowadays, forgot I changed that a while back.



    1.) Cleaned my AAI file

    2.) Started a 4-lap race using AAI with WTCC'13 BMW 320 at Hungaroring, 10 opponents, no data entries so level starts off at 85:
    1:57.710 was my average laptime, 2:08.076 was AI average laptime.

    3.) Doing same race again, there's one data entry now; then the crude calculation sets level at 96:
    1:57.971 was my average laptime, 1:59.951 was AI average laptime.

    4.) Doing same race again, there're two data entries now, both slower than my average; then extrapolation is used and sets level at 100:
    1:58.182 was my average laptime, 1:58.144 was AI average laptime.

    5.) Doing same race again, there're both slower and faster data entries now than my average; then interpolation between those entries are used and sets level at 100 again:
    1:56.479 was my average laptime, 1:57.800 was AI average laptime.

    6.) Doing same race again, there're only slower data entries now than my average; then extrapolation is used and sets level at 103:
    1:56.315 was my average laptime, 1:57.327 was AI average laptime.

    7.) Doing same race again, there're only slower data entries now than my average; then extrapolation is used and sets level at 107:
    1:55.554 was my average laptime, 1:56.019 was AI average laptime.

    8.) Doing same race again, there're only slower data entries now than my average; then extrapolation is used and sets level at 109 and so on.

    9.) Started a 4-lap race using AAI with WTCC'13 BMW 320 at Norisring, 10 opponents, no data entry for this combo but it takes average AAI level of all tracks it can find using that car, and only finds the one for Hungaroring, so sets level at 109. After race it gets updated to 114.

    10.) Started a 4-lap race using AAI with Ford Capri at Hungaroring, 10 opponents, no data entry for this combo but it takes average AAI level of all cars it can find using that track, and only finds the one for WTCC'13 BMW 320, so sets level at 109. After race it gets updated to 109.

    11.) Started a 4-lap race using AAI with a GTR3 car at Zandvoort, 10 opponents, no data entry for this combo but it takes average AAI level of all cars on all tracks; (109 + 114 + 109) / 3 = 110.
     
    • Like Like x 1
  15. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    Fair enough.
    It's certainly not outside the realm of possibility that I've been doing something wrong. The past few years I've simply been using editing/fixed AI instead of relying on the AAI, so something may have changed.
    I'll see if I can find the time to reproduce it in the near future.
    If not, I'll shut up about it. :D
     
    • Like Like x 1
  16. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    @Robert Holm You're absolutely right, I can't reproduce it either.
    So either something changed in a patch somewhere or, more likely, my initial methodology was flawed to begin with.
    Granted, I'd still like those early very low AI levels to be deleted from the index-file since they're never going to be used anyway, but that's just my OCD talking.
    At any rate, feel free to ignore me, I clearly don't know what I'm talking about. :D
     
    • Like Like x 1
    • Funny Funny x 1
    • Informative Informative x 1
  17. J-F Chardon

    J-F Chardon KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +5,041 / 0 / -0
    So, have you guys found an improvement after this last patch?
     
  18. CheerfullyInsane

    CheerfullyInsane Well-Known Member

    Joined:
    Oct 24, 2015
    Ratings:
    +402 / 0 / -0
    Haven't tried it yet, tbh.
    BattleTech got released which swallowed up my game time. :p
     
  19. Skidmark

    Skidmark Well-Known Member

    Joined:
    Oct 9, 2015
    Ratings:
    +232 / 0 / -0
    Definitely yes! Thank you @J-F Chardon and the team.

    My race results show that when I gave up on the Adaptive AI a month ago (see posts above! ;)) I had done four races in a row with consistent lap times in the 2:17 - 2:18 range (Bathurst). After each of those races the AI would run the next race in the mid 2:25s or worse (one in the 2:36s :eek:). [The probable reason was one or two very slow laps in the races caused by AI pile-ups at Skyline.]

    I have only had time for two races since the update but it looks very promising. :)

    First race straight out of the box (no training) the Adaptive AI was a bit off my pace running in the 2:19s and 20s.

    Second race - just completed - AI was bang on where I would have set it myself running in the 2:17s and 2:18s. :cool:

    I am hoping the next and subsequent races it stays there or goes a tiny bit quicker (I won a ten lap race from 6th on the grid by 1.6 seconds - so my adaptive-human response would have been to crank up the difficulty one notch…).

    Anyway - so far it's looking very good and a great improvement. Thanks again for being so responsive!!! :D:D:D
     
  20. J-F Chardon

    J-F Chardon KW Studios Developer

    Joined:
    Jan 15, 2015
    Ratings:
    +5,041 / 0 / -0
    Credits to @Robert Holm . I'm sure he'll be glad to hear it helped.