AI Development Discussion and Feedback


  • Admin

    @ubernaut would you mind jumping in on: https://github.com/triplea-game/triplea/issues/5792? We'd really like to get the problem object text wrapping fixed, but need more information and someone to work with to help us test any fixes. We're curious off the bat which UI Look & Feel you are using and confirmation that you're using Mac OS.


  • Moderators

    @LaFayette ok i'll reply there my name there is 'doctored'


  • Moderators Admin

    @Cernel said in AI Development Discussion and Feedback:

    It is also very slow deciding the purchase. I'm testing this on a map modification of 270BC I'm making, and I'll give more details once is out.

    Actually, the slowness appears to be some sort of major regression with the prerelease. Further testing reveal that, letting "Fast AI" play alone, these are the times to make the first 2 rounds (from clicking on "Play" till ending round 2):

    1.9.0.0.13066: 7 first and 45 second minutes.

    2.0.18267: 19 first and 32 second minutes.

    In both cases, I've assigned -Xmx8192M and -Xms8192M, that just means unlimited.

    The difference lays on the fact that, while the stable needs only a few seconds there, the prerelease takes an excruciatingly long time each "purchase" phase, to decide what to buy.

    On the other hand, the prerelease might be a little lighter on the RAM use, as I see it is at 3.32G at the end of round 2 for 1.9.0.0.13066 and 3.28G at the same point for 2.0.18267.


  • Admin

    @Cernel Ok. I would need to be able to test it myself so either need the map you are using or if you see the behavior on an existing map then I can take a look.


  • Admin

    @Cernel Stray thought, you may want to try -Xmx @ 2G or 3Gs. More memory is not always better. Usually there is not that much that needs to stay in memory, but memory is also not cleaned until it sometimes needs to be. The cost to clean memory when it is full is also non-linear, you could be seeing extremely long pauses while that happens.


  • Moderators Admin

    @LaFayette Actually, for 1.9.0.0, RAM usage goes down to 2.34G by the end of round 10. So, it seems the RAM is getting cleaned even if having a much bigger upper limit. Also very strange that it is using about 1G of RAM more at start game than after 10 rounds. Guess we can indagate the matter once I release the map, as this game has a lot of triggers.

    Once at that point, and preferably after @redrum fixes the purchase lag, I can also test it at different "xmx" settings, see what's faster.


  • Moderators Admin

    As said, in this game (270BC Wars, unreleased) each land territory has a factory in it, while what appears to be the factory is actually an itself useless unit that is required by most units for placement (so, you have some units that you can place anywhere, and some units only in factories, though they are not actually factories).

    Tested in call cases with:
    -Xmx4096M
    -Xms4096M
    All to Fast AI And with the "barbarians" player disabled.
    AI Pause Duration=250

    TripleA 18437 (4 days ago):
    Time to end the first turn (Carthage): 2' and 2"
    Time to end the first 5 rounds: 50' and 10"
    RAM level at the end of the first turn (Carthage): 2.08 GB
    RAM level at the end of the first 5 rounds: 2.92 GB

    TripleA 18511 (current):
    Time to end the first turn (Carthage): 0' and 38"
    Time to end the first 5 rounds: 15' and 46"
    RAM level at the end of the first turn (Carthage): 2.06 GB
    RAM level at the end of the first 5 rounds: 2.20 GB

    So, the Fast AI now plays over 3 times faster, and it seems it also uses 0.72 GB less of RAM, after 5 full rounds.

    The gains I believe are all on the purchase phases. For example, in 18437, the purchase phase of the first turn of Carthage lasted a painful 1 first and 19 seconds, while now the AI brezees throug it in 6 seconds: about 13 times faster!

    So, am I right assuming that these huge improvements in speed are thanks to this pull:
    https://github.com/triplea-game/triplea/pull/6086
    ?

    If so, great job and thank you @Alexei-Svitkine.


  • Admin

    @Cernel yep, that is correct and glad to see the drastic improvement!


  • Moderators Admin

    Also tested the current release 1.9.0.0.13066, under the same settings:
    -Xmx4096M
    -Xms4096M
    All to Fast AI And with the "barbarians" player disabled.
    AI Pause Duration=250
    (also -Dsun.java2d.opengl=true)

    TripleA 13066 (current release):
    Time to end the first turn (Carthage): 0' and 38"
    Time to end the first 5 rounds: 16' and 23"
    RAM level at the end of the first turn (Carthage): 1.84 GB
    RAM level at the end of the first 5 rounds: 2.32 GB

    Also, the purchase phase of the first turn of Carthage lasts only 6 seconds, here, just like in the latest prerelease.

    So, it seems that the current release and the latest prerelease have very similar speed and RAM usage, except that the prerelease might be a tad better in both (though, since the game plays differently virtually every time, small differences on a single game are not a reliable metre).

    In practice, it looks like something was done after the release that made the game over 3 times slower, while now either @Alexei-Svitkine fixed it or introduced some other improvements that just so happened to about exactly counter balance whatever else happened.


  • Admin

    @Cernel I think it the original slow down is probably related to changes in the path finding to better handle canals/terrain/etc. The AI was using this path finding itself in a not optimized way which now was further optimized.


  • Moderators Admin

    Hey, this is not much of a feedback, but just wanted letting you know I've for the first time played Feudal Japan all war (by editing all relationships to default war, so there is no politics) (you can see the edits in the Levy Initial Units phase), with also my usual addition of +2 castles in each capital (kinda needed, really).

    Savegame:
    03_WIN.tsvg

    It's the 1.9.0.0 release (13066) (we played live in the lobby).

    In this game, that lasted until round 18, none of the 4 players even get the chance to come next to each other, nor on land, neither on sea.

    Eventually, I won because everyone else got stomped by the AI.😆

    The first human player to become history was Yamana, stomped by the AI on round 9, despite the fact that we edited him back 3 daimyo (!!!) on round 3 (he lost the first 2 on round 1 and the last one on round 3). Obviously, he was a noob.

    Then, it was the turn of Ryuzoji, stomped by the AI on round 12. An average (maybe good) player, but inexperienced on the map.

    Then, the AI partially stomped Chosokabe in Iyo on round 18, and that player surrendered, ending the game in my favour by survival.😅

    And we were not even playing with any AI bonuses at all! As you can see, I've dumped all the flags into the "Human Players" box (that is how you avoid anyone getting bonuses).

    I'm Hojo and, at this point, I think I should (very) slowly but surely conquer all Japan, as long as no major mistakes, but Shimazu might have a chance of snowballing out of control (I might keep playing the game against the AI, to see how it goes on).

    So, while the AI, apparently, was more successful than most players (as said, this is 100% fair, as the AI didn't have any bonus at all), it still did some major mistakes, that I wish to highlight:

    1. On round 1, Uesugi attacks Kokuze, putting itself in a major dead zone, basically easily losing its own game on its first move. I actually attacked that AI player in that zone, on round 2, but only to strafe it, to damage it and, therefore, oblige it to turtle for the rest of the game, as, then, Date, would inevitably be next to its capital. Anyways, that was a very bad decision to take, and the AI does it quite often: attacking the "neutral" player just to end up in a zone where to be attacked at huge TUV loss (eventually, Uesugi fell earlier than I hoped, to Date, hence I'm not sure that strafe was a good idea, but ended up being manageable, mostly out of major misplays from Date, as well).

    2. On round 12 Date attacks the "Neutrals" in Etchu, which is itself not something terrible, as it loses 5 ashigaru in exchange for getting an easily defensive 3 production territory, opening up to two other exposed production 3 territories, but, at the same time, it also attacks Kozuke, on a 88% battle, that would be very bad if failing and not much better if succeeding, as I've my huge stack nearby. That is the single move that spelled the fate of Date (if the game would have lasted a few more rounds, I would have got Date capital on a 100% on dice). More in general, I believe the AI displays an excessive tendency to attack those "minor clans". I don't recall if the logic to see and deprioritize players having no combat move phases is already there in the release or not? If it is, it is not working enough.

    3. The castle are really good units here, combining each one with 3 ashigaru (as you can see, I consistently bought them), but the AI never buys them (I know, immobile units, it will be needed to see what 2.0 does here).

    4. The AI seems unable to see the basic importance of the ashigaru units, buying too few of them and, consequently, having way more units able to give support than units able to receive support (needs some logic giving value to the ability of receiving support maybe?). What I suppose the AI is missing, here, also, is the importance of the Daimyo "infinite" bonus. Since that raises of 1 the power of each unit, it follows that the ashigaru are really much better units than basic stats, because that is double power for them, while much less of a bonus the more the units themselves are powerful. The AI doesn't even have a placement excuse for this, as here you can place anywhere (each territory has an invisible factory unit).

    5. The AI very rarely buys cavalry, despite this being a fairly good unit. If you look at the stats and compare it with samurai (that the AI buys more frequently), you can see that if a samurai costs 6, the cavalry may cost 7, if it would move 1, thus it is only overpriced by 1, in exchange for the movement 2. I don't buy cavalry often, either, but it seems the AI almost completely refuses to buy them, and that's too extreme.


  • Admin

    @Cernel Good feedback. I'll take a look at some of these. I think some are related to the somewhat minimal AI FFA logic where it still tends to be a bit over aggressive in trading. And yes, the AI does have some improvements in 2.0 so should be even better and should now at least consider buying castles.


  • Moderators Admin

    @redrum Ok. I believe that, beside politics, the only 2 major issues are (about as important) the tendency to lose huge amount of TUV to kill super-stacked "Minor Clans" territories (probably the AI should just check if the player has a "Conduct Combat" phase, and treat it as a Neutral if it doesn't) and the fact that it buys very few Ashigaru (the best unit in the game). If only these two would be fixed, then the AI would become a true nightmare, on that map, without politics.

    I think the ability of receiving support should be valued just as much as the ability of giving support. It is really next to irrelevant who is giving and who is receiving: the precious one is whatever of the two that is in the shortest supply. So, practically, what the AI should do is to see what are the units that are going to be bought in the biggest numbers, between givers and receivers, then give the support bonus value to the other one (no matter if a giver or a receiver). For example, in the basic games, we have infantry 1/2 cost 3 and artillery 2/2 cost 4. In this case, the infantry is better than the artillery on the basic stats, so the artillery gets a bonus value for being able to give support. However, if the infantry would be 1/2 cost 3 and the artillery 2/1 cost 3, then the bonus value (to buy some more of them) should be given to the one that, on basic stats, you would buy the least (in this case depending if you need defence or offence). For example, if you need offence, thus are buying many more 2/1 artilleries than 1/2 infantries, then the infantries should receive a value bonus for being able to receive support. As you can see, if you have more artilleries than infantries, each new infantry you by is practically a 2/2 unit, while each artillery you buy is practically a 2/1 unit. In this case, actually, it should never happen that you buy more artilleries than infantries, no matter how much you are attack oriented (because, as long as you have more artilleries, infantry is just the same as artillery, but with more defence for free).

    Of course, the AI should see who is in the shortest supply with reference to how many can be supported. The Daimyo is a good case, since it supports a virtually infinite number of any other units. Thus it is the other units that should receive a value boost for being able to receive support (as they are surely the ones in the shortest supply, since the Daimyo can always support more) and, amongst them, the boost should induce the AI to buy more Ashigaru than other units, since 1 Ashigaru is just as good as using the available support, while it costs less, thus you can get more support bonuses, for the same TUV.

    I definitely not suggest changing the AI as to make it more fodder oriented, as I see, on other maps, the AI rather buys too few pricey units. So, here, it is just a matter of not valuing the ability of receiving support, which matters thrice (!) over for the Ashigaru (since they receive by other units and by daimyo and by castles, all these 3 supports stacking).

    The main way I usually use castle, there, is, for example, by having 1 castle and 3 ashigaru in a territory next to a huge stack of mine that is able to deadzone the territory with the castle. This way, the enemy cannot go massively into it (the AI will not do it) and, at the same time, taking it with limited forces, especially in dice, is a really bad deal, because, even on a 95% success or so (and if it fails it is terrible), you would have to use way much more TUV than the TUV value of the defending units, just to, then, getting killed back by the nearby stack. So, that, in a FFA, basically should assure that no rational player will take such a territory, under these conditions, therefore I can keep the precious production and slowly edging up on TUV (that is most of what this game is about), while, meanwhile, the AI keeps attacking and counter-attacking each other, thus progressively getting behind me in TUV, until I got enough superiority to go for killing some capital.

    On the other hand, putting castles in your capital is usually something that you do after you messed up something, as, next to your capital, you really need eventually to deadzone, not turtle behind castles (but I change the game by editing +2 castles in each capital, to make it better playable).

    As I said, this is only beside politics, because, if you play with politics, you can just spam your politic actions to get the AI you want to Allied and, once they are allied, it is maybe something like 1% that they ever downgrade from Allied (why is the AI coded so strongly against downgrading from Allied), so you have these Allied players, that play like it is not a FFA at all (they clearly play like they are forever Allies, like in 2 sides games), and, at the right moment, you can build up on their capital and go to war and take the capital and easy destroy them, while they are afar fighting your wars. This game was a challenge because we went no politics (all war) (with the edits, since this is not actually an option). The game is way easier if you can take advantage of the AI dumbness in navigating FFA politics. Really not even a challenge at all, with politics on, unless you are a huge noob.


  • Moderators Admin

    @Cernel said in AI Development Discussion and Feedback:

    As said, in this game (270BC Wars, unreleased) each land territory has a factory in it, while what appears to be the factory is actually an itself useless unit that is required by most units for placement (so, you have some units that you can place anywhere, and some units only in factories, though they are not actually factories).

    Tested in call cases with:
    -Xmx4096M
    -Xms4096M
    All to Fast AI And with the "barbarians" player disabled.
    AI Pause Duration=250

    TripleA 18437 (4 days ago):
    Time to end the first turn (Carthage): 2' and 2"
    Time to end the first 5 rounds: 50' and 10"
    RAM level at the end of the first turn (Carthage): 2.08 GB
    RAM level at the end of the first 5 rounds: 2.92 GB

    TripleA 18511 (current):
    Time to end the first turn (Carthage): 0' and 38"
    Time to end the first 5 rounds: 15' and 46"
    RAM level at the end of the first turn (Carthage): 2.06 GB
    RAM level at the end of the first 5 rounds: 2.20 GB

    I've seen @Alexei-Svitkine squeezed some more juice, recently, so did a new test (the game is virtually the same):

    TripleA 18843:
    Time to end the first turn (Carthage): 0' and 29"
    Time to end the first 5 rounds: 13' and 21"
    RAM level at the end of the first turn (Carthage): 1.94 GB
    RAM level at the end of the first 5 rounds: 2.29 GB

    So, the Fast AI now takes only 85% the time as before.

    Nice.


  • Admin

    @Cernel Yeah, his optimizations have focused on AI areas outside of the BC which you'll see have a greater percentage improvement on the Fast AI but should impact Hard AI as well (just not as noticeable since BC is like 80-90% of the Hard AI time). But good to see the improvements are making a difference.


  • Admin

    @redrum Out of curiosity... 🤔

    can or how does the AI purchase-value cost-effectiveness of a unit and it's target AA attacks, when these AS attacks are sometimes limited to hit certain targets?

    Also, how does AI purchase- value a units support abilities, when these also sometimes are only given to a select group/unit types?



  • Glad to see my improvements helping so much!

    There is at least one more coming which should help a lot too. I just sent a PR for it this morning.


  • Admin

    @Frostion said in AI Development Discussion and Feedback:

    can or how does the AI purchase-value cost-effectiveness of a unit and it's target AA attacks, when these AS attacks are sometimes limited to hit certain targets?

    No, currently the AI doesn't value AA attacks.

    Also, how does AI purchase- value a units support abilities, when these also sometimes are only given to a select group/unit types?

    It does some calculations to try to determine how many units give support of that type and receive support of that type within a radius around the factory its looking to place units. Based on that it gives some value between 0 and close to 100% of the support value. So an example is if I have lots of infantry and no artillery then value the artillery support close to a normal attack value vs if I have lots of artillery and no infantry then value the artillery support as worth close to 0.


  • Moderators Admin

    @Alexei-Svitkine said in AI Development Discussion and Feedback:

    Glad to see my improvements helping so much!

    There is at least one more coming which should help a lot too. I just sent a PR for it this morning.

    @Cernel said in AI Development Discussion and Feedback:

    TripleA 18843:
    Time to end the first turn (Carthage): 0' and 29"
    Time to end the first 5 rounds: 13' and 21"
    RAM level at the end of the first turn (Carthage): 1.94 GB
    RAM level at the end of the first 5 rounds: 2.29 GB

    Still tested with:
    -Xmx4096M
    -Xms4096M
    All to Fast AI and with the "barbarians" player disabled.
    AI Pause Duration=250

    TripleA 18871:
    Time to end the first turn (Carthage): 0' and 32"
    Time to end the first 5 rounds: 13' and 48"
    RAM level at the end of the first turn (Carthage): 1.94 GB
    RAM level at the end of the first 5 rounds: 2.03 GB

    So, this time it took slightly more time, actually (but maybe just a coincidence, as virtually no games go the same way), but it seems there is an 11% reduction in the RAM allocated, after finishing 5 rounds.



  • Not sure if helpful, but I have another example of some bad AI strategy.

    This time on Domination 1914. This from a 2.0 prerelease, unfortunately before the recent Unit + TripleAUnit merge, so to load the save, you need a slightly older version (e.g. prerelease/checkout at 2.0.18893 for example).

    In this game, I was playing as Communists and all other players were Hard AI. The central powers did really well, in particular because USA wasn't able to ever get in the game (it just amassed planes in USA that never made it to somewhere relevant - despite it being possible to island-hop them to Europe/Africa). For example 71 planes in Charleston (there's another 50 in Aleutian Islands):

    Screen Shot 2020-04-27 at 10.49.43 PM.png

    As Communists, I conquered all of Russia, creating a border of my territories against the central powers. So they just kept amassing land units there, not sure why - since they can't enter my territory so they were kind of stuck there. They didn't try to build transports to get those units somewhere useful.

    Screen Shot 2020-04-27 at 10.50.05 PM.png

    On the other hand, when Europe was fully captured, Germany did a hard turn in its production, going from building mostly ground units to building something like 15 planes a turn. But then it ended up in some awkward situations where Britain kept taking some territories with land units and transport and Germany having no neighbouring land units but like 40 planes, to recapture. Germany could have defended things much better.

    Screen Shot 2020-04-27 at 11.10.03 PM.png

    Arabia was particularly interesting - due to Turkey not playing very well, Arabia kept managing to stay alive and harass them. However, its capital could only produce 4 units, which it was doing to produce 4 Beaudoin units each turn. But it had more money than that - so it was just building up a war chest for no reason (as opposed to using it - e.g. building a factory somewhere or just dumping intro trenches that could be built without a factory).

    One turn UK loaded up some units on a transport and just left it in open waters sinkable by my plane. Even though those units could have landed in an undefended territory instead (e.g. Latvia)!

    Screen Shot 2020-04-27 at 10.41.20 PM.png

    Another thing, at some point different countries like UK, Austria, Germany, USA built navies. But ship choices were rather poor - mostly building Cruisers - but ideally for large fleets, you want to have battleships to take hit points without dying - the computer was not doing that.

    I'm sure there's lots of other questionable stuff there, but the above are some of the most glaring.

    dom_AI.tsvg.zip


Log in to reply