<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Development Discussion: Speeding up battle calculator (and thus Hard AI)]]></title><description><![CDATA[<p dir="auto">Not sure if this is the best place to discuss this, since this is a more of a technical discussion on the code side as opposed to user-visible features...</p>
<p dir="auto">Anyway, with the recent investigation into performance related to the battle calculator that's heavily used by Hard AI, I figured it's worth to discussing what would be the ideal implementation that could be much faster.</p>
<p dir="auto">When battles are simulated, a copy of the game data (every state in the game) is made, so that when we perform battles in simulation, they don't change the real game. Obviously, this is really slow. So how can we make this better?</p>
<p dir="auto">It seems there's a few ways to approach this - that could potentially be combined together.</p>
<ol>
<li>
<p dir="auto">We could try to do fewer calculations. For example, I added some logging code about what was being calculated and noticed some duplicates - the same battle was being calculated during two different parts of moveUnitsToDefendTerritories() (calculateBattleResults() called directly from there and through estimateDefendBattleResults()). So perhaps some kind of cache.</p>
</li>
<li>
<p dir="auto">We could even generalize this further if we're careful - for example, if we're already simulated the attack of a given force against 2 infantry, that result could be re-used for a battle at a different territory that's also defended by two infantry. The challenge is of course taking into account anything that might affect the battle result (which may be hard to reason about all - since there's so many different techs and game rules - e.g. fighter scramble, that we'd probably need to enumerate them all somewhere and classify which can affect battles to decide what information needs to be taken into account of).</p>
</li>
<li>
<p dir="auto">When copying game data, we could copy things selectively. For example, we probably just need all the technology and the territories involved in combat (which may need to include adjacent territories for scramble?). However, for this, we'd need custom copy logic instead of just serializing everything.</p>
</li>
<li>
<p dir="auto">We can try not to copy the game data. For this to work, we would need to ensure several things:<br />
a. That the combat code doesn't directly modify GameData but instead does it through an abstraction that we can have a custom implementation of.<br />
b. That the battle calc isn't being done at the same time as the real GameData is changing. Assuming (a) is already in place, this should be safe to assume if battle calc is being done by the AI on its turn, but not if the player is using the battle calc (because they may not be the active player - or in theory they could bring up battle calc while doing their moves in parallel). So we'd still need to support a mode that does copy GameData, but for the purposes of Hard AI (which is what's slowed down the most by battle calc), we could have the fast mode.</p>
</li>
</ol>
<p dir="auto">Any other ideas? I'm thinking that (4) actually seems the most promising. We could start with a boolean flag on the battle calc that specifies not to copy game data and audit all the places that the Fight code is making changes back to GameData that need to be intercepted. In terms of keeping state, as long as the Fight code is keeping its own state (e.g. which units are left in the battle, etc), rather than querying it from the Territories and such, I think it may be pretty doable. I can look into it.</p>
]]></description><link>https://forums.triplea-game.org/topic/1944/development-discussion-speeding-up-battle-calculator-and-thus-hard-ai</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 03:49:11 GMT</lastBuildDate><atom:link href="https://forums.triplea-game.org/topic/1944.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 03 May 2020 13:07:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Wed, 20 May 2020 16:56:40 GMT]]></title><description><![CDATA[<p dir="auto">I've created a PR - <a href="https://github.com/triplea-game/triplea/pull/6501" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/triplea-game/triplea/pull/6501</a></p>
]]></description><link>https://forums.triplea-game.org/post/38016</link><guid isPermaLink="true">https://forums.triplea-game.org/post/38016</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Wed, 20 May 2020 16:56:40 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 19:11:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/roiex" aria-label="Profile: RoiEX">@<bdi>RoiEX</bdi></a> deleting the <code>assets</code> and <code>.assets</code> fixed the issue.</p>
]]></description><link>https://forums.triplea-game.org/post/37967</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37967</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Tue, 19 May 2020 19:11:16 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 19:10:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/roiex" aria-label="Profile: RoiEX">@<bdi>RoiEX</bdi></a> It looks like IntelliJ is running that command but I ran it manually as well.  I'm still getting that error.  There are other files in <code>game-headed/assets/unit_scroller</code> so things have been downloaded.</p>
]]></description><link>https://forums.triplea-game.org/post/37966</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37966</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Tue, 19 May 2020 19:10:11 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 19:10:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/trevan" aria-label="Profile: Trevan">@<bdi>Trevan</bdi></a> If you're using intelliJ then it should automatically download the assets.<br />
Try deleting the <code>assets</code> and <code>.assets</code> folder and it should force a re-download</p>
]]></description><link>https://forums.triplea-game.org/post/37965</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37965</guid><dc:creator><![CDATA[RoiEX]]></dc:creator><pubDate>Tue, 19 May 2020 19:10:10 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 19:06:21 GMT]]></title><description><![CDATA[<p dir="auto">And yes, you can create a PR whenever you like, it will take us a while to review it though</p>
]]></description><link>https://forums.triplea-game.org/post/37964</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37964</guid><dc:creator><![CDATA[RoiEX]]></dc:creator><pubDate>Tue, 19 May 2020 19:06:21 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 19:06:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/roiex" aria-label="Profile: RoiEX">@<bdi>RoiEX</bdi></a> I'm using IntelliJ</p>
]]></description><link>https://forums.triplea-game.org/post/37963</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37963</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Tue, 19 May 2020 19:06:12 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 19:05:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/trevan" aria-label="Profile: Trevan">@<bdi>Trevan</bdi></a> are you using a specific IDE?<br />
I think you have to run<br />
<code>./gradlew downloadAssets</code> before running the game in order to download all the default assets</p>
]]></description><link>https://forums.triplea-game.org/post/37962</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37962</guid><dc:creator><![CDATA[RoiEX]]></dc:creator><pubDate>Tue, 19 May 2020 19:05:20 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 18:57:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/roiex" aria-label="Profile: RoiEX">@<bdi>RoiEX</bdi></a> That worked.  I have to restart triplea for it to affect.</p>
<p dir="auto">I tried to play a game in the UI since everything I've done has been through the test framework.  But when I try to start a game, I get the error</p>
<pre><code>Failed to start game
IllegalArgumentExeption: File must exist at path: /.../game-headed/assets/unit_scroller/unit_sleep.png
</code></pre>
<p dir="auto">I've checked and that file definitely doesn't exist.  I've also checked out master and tried to run it in case my changes broke it but master also throws that same error.</p>
<p dir="auto">Is there something I'm missing?</p>
<p dir="auto">And should I create a PR now?</p>
]]></description><link>https://forums.triplea-game.org/post/37960</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37960</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Tue, 19 May 2020 18:57:05 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 18:26:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/trevan" aria-label="Profile: Trevan">@<bdi>Trevan</bdi></a><br />
Looks like <a class="plugin-mentions-user plugin-mentions-a" href="/user/lafayette" aria-label="Profile: LaFayette">@<bdi>LaFayette</bdi></a> trolled you a little bit there.<br />
Try</p>
<pre><code class="language-java">BATTLE_TREE_AI("BattleTree (AI)", ClientSetting.showBetaFeatures.getValue().orElse(false)) {
  @Override
  public Player newPlayerWithName(final String name) {
    return new BattleTreeAi(name);
  }
},
</code></pre>
<p dir="auto">instead</p>
]]></description><link>https://forums.triplea-game.org/post/37956</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37956</guid><dc:creator><![CDATA[RoiEX]]></dc:creator><pubDate>Tue, 19 May 2020 18:26:23 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Tue, 19 May 2020 18:04:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lafayette" aria-label="Profile: LaFayette">@<bdi>LaFayette</bdi></a> I tried using that in the PlayerType enum</p>
<pre><code>  BATTLE_TREE_AI("BattleTree (AI)", ClientSetting.showBetaFeatures.isSet()) {
    @Override
    public Player newPlayerWithName(final String name) {
      return new BattleTreeAi(name);
    }
  },
</code></pre>
<p dir="auto">But the player is still showing up in the list.</p>
<p dir="auto">I also tried:</p>
<pre><code>  BATTLE_TREE_AI("BattleTree (AI)") {
    @Override
    public Player newPlayerWithName(final String name) {
      if (ClientSetting.showBetaFeatures.isSet()) {
        return new BattleTreeAi(name);
      }
    }
  },
</code></pre>
]]></description><link>https://forums.triplea-game.org/post/37955</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37955</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Tue, 19 May 2020 18:04:35 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Sun, 17 May 2020 19:25:12 GMT]]></title><description><![CDATA[<pre><code>    if(ClientSetting.showBetaFeatures.isSet()) {
        // add experimental feature
    }
</code></pre>
]]></description><link>https://forums.triplea-game.org/post/37832</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37832</guid><dc:creator><![CDATA[LaFayette]]></dc:creator><pubDate>Sun, 17 May 2020 19:25:12 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Sun, 17 May 2020 19:11:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/roiex" aria-label="Profile: RoiEX">@<bdi>RoiEX</bdi></a> I'm not aware of the test flag.  How do I use it?</p>
<p dir="auto">I can make a sibling of FastAI that uses this calculator.  I also like the idea of having it automatically compare the actual odds vs the new odds.  <a class="plugin-mentions-user plugin-mentions-a" href="/user/alexei-svitkine" aria-label="Profile: Alexei-Svitkine">@<bdi>Alexei-Svitkine</bdi></a> when you say "send error reports", how would I do that?  Is there existing classes in the code that I can just use to send the reports?</p>
]]></description><link>https://forums.triplea-game.org/post/37830</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37830</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Sun, 17 May 2020 19:11:25 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Sat, 16 May 2020 18:56:14 GMT]]></title><description><![CDATA[<p dir="auto">An AI variant IMO would be an excellent step. The idea of computing the actual odds vs the current monte carlo approximation is a very good one.</p>
<p dir="auto">The combat/battles code suffers from complexity and is already somewhat time-optimized. It would be very easy to underestimate the level of effort to replace the battle calc (simply having something that mostly works is just not quite enough, it would need to be cleanly coded, not be duplicative, well tested, complete, etc...)</p>
]]></description><link>https://forums.triplea-game.org/post/37767</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37767</guid><dc:creator><![CDATA[LaFayette]]></dc:creator><pubDate>Sat, 16 May 2020 18:56:14 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Sat, 16 May 2020 12:55:26 GMT]]></title><description><![CDATA[<p dir="auto">Perhaps it could be added as a checkbox in the battle calculator for now as well?</p>
<p dir="auto">Otherwise, I think the two things it needs is a heuristic for when it should be used (e.g. if too many units or when there are unsupported cases, it should do the usual battle calculator instead) and some kind of way to find cases where it disagrees with battle calculator. For example, maybe run some percentage of simulations using both and send error reports when the results disagree too much? Or perhaps we can have an experimental AI that always runs both so we can use it to validate it and find cases where it's incorrect?</p>
]]></description><link>https://forums.triplea-game.org/post/37755</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37755</guid><dc:creator><![CDATA[Alexei Svitkine]]></dc:creator><pubDate>Sat, 16 May 2020 12:55:26 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Sat, 16 May 2020 12:22:50 GMT]]></title><description><![CDATA[<p dir="auto">I'm not 100% sure what <a class="plugin-mentions-user plugin-mentions-a" href="/user/redrum" aria-label="Profile: redrum">@<bdi>redrum</bdi></a>'s opinion on this is, but I'd really like to see this as an experimental Ai in the game.<br />
But for now hide it behind the test flag?</p>
]]></description><link>https://forums.triplea-game.org/post/37753</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37753</guid><dc:creator><![CDATA[RoiEX]]></dc:creator><pubDate>Sat, 16 May 2020 12:22:50 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Sat, 16 May 2020 03:30:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/redrum" aria-label="Profile: redrum">@<bdi>redrum</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/roiex" aria-label="Profile: RoiEX">@<bdi>RoiEX</bdi></a><br />
I think I have a good majority of the battle logic done.  I know I'm missing bombardment, some details in sub first strike (order of strikes and destroyers presence), transport handling, amphibious battles, and paratroopers.  There's probably other complexities that I missed as well.  I've also worked on speeding it up.  Here's a bunch of comparisons:</p>
<pre><code>30 infantry, 30 artillery, 30 armour, 30 fighter, 30 tactical_bomber, 30 bomber vs same
MiniMax: 21218.5 ms, Win: 0.9779225005914358, Lose: 0.021637464729431084
BattleCalculator: 1841.4 ms, Win: 0.95, Lose: 0.045
Hard AI 200 runs: 2893.2 ms, Win: 0.955, Lose: 0.045
Hard AI 2000 runs: 7900.4 ms, Win: 0.970703125, Lose: 0.029296875
FastOdds: 29.4 ms, Win: 0.6517051232809282, Lose: 0.0

10 infantry, 10 artillery, 10 armour, 10 fighter, 10 tactical_bomber, 10 bomber vs same
MiniMax: 1342.4 ms, Win: 0.8637259513264075, Lose: 0.131552773090954
BattleCalculator: 459.2 ms, Win: 0.895, Lose: 0.105
Hard AI 200 runs: 1280.3 ms, Win: 0.87, Lose: 0.12
Hard AI 2000 runs: 2414.4 ms, Win: 0.8486328125, Lose: 0.1455078125
FastOdds: 7.4 ms, Win: 0.6286565968532855, Lose: 0.0

1 infantry, 1 armour vs 2 infantry
MiniMax: 1.4 ms, Win: 0.506233909545216, Lose: 0.38491296598075025
BattleCalculator: 74.3 ms, Win: 0.505, Lose: 0.365
Hard AI 200 runs: 987.0 ms, Win: 0.495, Lose: 0.39
Hard AI 2000 runs: 1000.7 ms, Win: 0.501953125, Lose: 0.3974609375
FastOdds: 0.5 ms, Win: 0.5, Lose: 0.0

1 armour, 1 tactical_bomber vs 2 infantry, 1 fighter
MiniMax: 1.2 ms, Win: 0.11504593215712659, Lose: 0.7947330200775955
BattleCalculator: 99.8 ms, Win: 0.115, Lose: 0.775
Hard AI 200 runs: 1156.5 ms, Win: 0.175, Lose: 0.75
Hard AI 2000 runs: 1244.3 ms, Win: 0.1201171875, Lose: 0.7958984375
FastOdds: 0.2 ms, Win: 0.34082222539412593, Lose: 0.0

1 infantry, 1 artillery vs 2 infantry
MiniMax: 1.0 ms, Win: 0.4574200859119973, Lose: 0.45742008591199734
BattleCalculator: 84.5 ms, Win: 0.49, Lose: 0.44
Hard AI 200 runs: 1095.0 ms, Win: 0.51, Lose: 0.41
Hard AI 2000 runs: 1231.1 ms, Win: 0.4619140625, Lose: 0.443359375
FastOdds: 0.2 ms, Win: 0.5, Lose: 0.0

1 cruiser, 1 destroyer vs 1 cruiser, 1 destroyer
MiniMax: 2.2 ms, Win: 0.4250031963247701, Lose: 0.4250031963247701
BattleCalculator: 86.0 ms, Win: 0.395, Lose: 0.44
Hard AI 200 runs: 1076.7 ms, Win: 0.405, Lose: 0.465
Hard AI 2000 runs: 1213.1 ms, Win: 0.4306640625, Lose: 0.4189453125
FastOdds: 0.4 ms, Win: 0.5, Lose: 0.0

1 cruiser, 1 destroyer, 1 battleship vs 2 cruiser, 1 destroyer
MiniMax: 3.9 ms, Win: 0.7898869382202083, Lose: 0.14239504638191994
BattleCalculator: 122.6 ms, Win: 0.76, Lose: 0.125
Hard AI 200 runs: 1076.1 ms, Win: 0.79, Lose: 0.15
Hard AI 2000 runs: 1188.0 ms, Win: 0.79296875, Lose: 0.1474609375
FastOdds: 0.7 ms, Win: 0.6591777746058741, Lose: 0.0

1 infantry, 1 fighter vs 1 infantry, 1 aa gun
MiniMax: 11.1 ms, Win: 0.5600126123377998, Lose: 0.35180777879589964
BattleCalculator: 189.6 ms, Win: 0.585, Lose: 0.315
Hard AI 200 runs: 1127.4 ms, Win: 0.595, Lose: 0.335
Hard AI 2000 runs: 1410.4 ms, Win: 0.5869140625, Lose: 0.3203125
FastOdds: 0.3 ms, Win: 0.7180577051181194, Lose: 0.0
</code></pre>
<p dir="auto">All of the win percentages are pretty darn close.  The 30 of each unit type battle was slower than the original calculator (21 seconds vs 3 seconds) but the 10 of each unit type battle was about the same (1.34 seconds vs 1.28 seconds).  The rest of the battles I did were small so it was a lot faster.</p>
<p dir="auto">What would you like me to do now?  Can I make this available to others (such <a class="plugin-mentions-user plugin-mentions-a" href="/user/swampy" aria-label="Profile: Swampy">@<bdi>Swampy</bdi></a>) so they can test it out?</p>
]]></description><link>https://forums.triplea-game.org/post/37748</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37748</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Sat, 16 May 2020 03:30:14 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Fri, 15 May 2020 10:19:06 GMT]]></title><description><![CDATA[<p dir="auto">Since I play against the AI quite a bit.. would love this project to succeed as Hard AI is ridiculously slow on large maps/lots of units. Would like to contribute.. but have very little coding skill unfortunately. If you need testers or other basic help... let me know.</p>
]]></description><link>https://forums.triplea-game.org/post/37703</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37703</guid><dc:creator><![CDATA[Swampy]]></dc:creator><pubDate>Fri, 15 May 2020 10:19:06 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Thu, 14 May 2020 03:53:06 GMT]]></title><description><![CDATA[<p dir="auto">AA guns were a lot harder than I expected but I think I got the majority of it working.  I did a comparison on the TestMapGameData.TWW data because it had units that could do aa firing with different target groups.  I ran a battle between an infantry, tank, and fighter vs an anti-tank gun, mobile artillery, and anti-air gun.</p>
<p dir="auto">MiniMax: 197.7 ms, Win: 0.5520100874509435, Lose: 0.40334641519178716<br />
Hard AI 200 runs: 2025.6 ms, Win: 0.57, Lose: 0.42<br />
Hard AI 2000 runs: 3222.8 ms, Win: 0.5517578125, Lose: 0.412109375<br />
FastOdds: 7.9 ms, Win: 0.7703534497836491, Lose: 0.0</p>
<p dir="auto">Now I'll work on multi-hit units.</p>
]]></description><link>https://forums.triplea-game.org/post/37669</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37669</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Thu, 14 May 2020 03:53:06 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Fri, 08 May 2020 00:08:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alkexr" aria-label="Profile: alkexr">@<bdi>alkexr</bdi></a> yes, my algorithm is assuming the order of losses is linear.  I believe the time is roughly what you said.  Each target group will have its own order of loss.</p>
]]></description><link>https://forums.triplea-game.org/post/37288</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37288</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Fri, 08 May 2020 00:08:24 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Thu, 07 May 2020 23:40:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/trevan" aria-label="Profile: Trevan">@<bdi>Trevan</bdi></a> Hmm, right, you can actually do this in cubic (?) time, so long as the order of losses is linear, because the number of casualties already sustained uniquely determines the composition of the remaining army. But I still don't see how you do it in less than <em>(number of units)^(number of target lists * constant)</em> time, where target lists include normal attacks, AA attack types, canNotBeTargetedBy and related mechanics, etc. Because, without assuming something about the order in which units die, technically there are a million different army compositions strictly smaller than "10 of each land type", as opposed to 60 if you assume a linear order of losses.</p>
]]></description><link>https://forums.triplea-game.org/post/37287</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37287</guid><dc:creator><![CDATA[alkexr]]></dc:creator><pubDate>Thu, 07 May 2020 23:40:02 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Sat, 16 May 2020 03:32:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alkexr" aria-label="Profile: alkexr">@<bdi>alkexr</bdi></a> here's some numbers of larger groups:</p>
<pre><code>10 infantry, 10 artillery vs same
MiniMax: 219.3 ms, Win: 0.497401100632783, Lose: 0.4974011006327829
Hard AI 200 runs: 2092.2 ms, Win: 0.475, Lose: 0.515
Hard AI 2000 runs: 2086.4 ms, Win: 0.4658203125, Lose: 0.5283203125
FastOdds: 8.9 ms, Win: 0.5, Lose: 0.0
20 infantry, 20 artillery vs same
MiniMax: 585.7 ms, Win: 0.49887594912628747, Lose: 0.49887594912628747
Hard AI 200 runs: 2538.8 ms, Win: 0.54, Lose: 0.46
Hard AI 2000 runs: 3255.3 ms, Win: 0.5029296875, Lose: 0.494140625
FastOdds: 14.7 ms, Win: 0.5, Lose: 0.0
30 infantry, 30 artillery vs same
MiniMax: 1244.4 ms, Win: 0.49930484393068525, Lose: 0.49930484393068525
Hard AI 200 runs: 2873.4 ms, Win: 0.5, Lose: 0.5
Hard AI 2000 runs: 3627.7 ms, Win: 0.501953125, Lose: 0.49609375
FastOdds: 15.5 ms, Win: 0.5, Lose: 0.0
40 infantry, 40 artillery vs same
MiniMax: 2032.1 ms, Win: 0.4995101769999315, Lose: 0.4995101769999315
Hard AI 200 runs: 2904.5 ms, Win: 0.505, Lose: 0.49
Hard AI 2000 runs: 4244.6 ms, Win: 0.51171875, Lose: 0.48828125
FastOdds: 16.9 ms, Win: 0.5, Lose: 0.0
50 infantry, 50 artillery vs same
MiniMax: 3366.8 ms, Win: 0.4996227075274397, Lose: 0.4996227075274401
Hard AI 200 runs: 3574.4 ms, Win: 0.49, Lose: 0.51
Hard AI 2000 runs: 4614.9 ms, Win: 0.4853515625, Lose: 0.5146484375
FastOdds: 16.8 ms, Win: 0.5, Lose: 0.0
60 infantry, 60 artillery vs same
MiniMax: 5306.7 ms, Win: 0.4996976675867421, Lose: 0.4996976675867422
Hard AI 200 runs: 3264.8 ms, Win: 0.54, Lose: 0.46
Hard AI 2000 runs: 5255.6 ms, Win: 0.4931640625, Lose: 0.5068359375
FastOdds: 22.5 ms, Win: 0.5, Lose: 0.0
10 infantry, 10 artillery, 10 armour, 10 fighter, 10 tactical_bomber, 10 bomber vs same
MiniMax: 12470.0 ms, Win: 0.8637525783579469, Lose: 0.13152813492843518
Hard AI 200 runs: 2565.5 ms, Win: 0.32, Lose: 0.68
Hard AI 2000 runs: 2721.8 ms, Win: 0.3125, Lose: 0.6875
FastOdds: 23.4 ms, Win: 0.6286565968532855, Lose: 0.0
</code></pre>
<p dir="auto">Interesting that the battle with 30 infantry and artillery was a lot faster than the one with 10 of each land type.  Both battle has a total of 60 units on both sides but the addition of multiple unit types slowed it down.</p>
]]></description><link>https://forums.triplea-game.org/post/37282</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37282</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Sat, 16 May 2020 03:32:26 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Thu, 07 May 2020 21:03:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/trevan" aria-label="Profile: Trevan">@<bdi>Trevan</bdi></a> Unfortunately this sort of algorithm has to be exponentially slow as the number of units increases, by its nature. I'm saying this without even looking at the code. With some cleverness it might be possible to bring this down to exponential with the number of unit types (not units), but will never be able to handle if, say, a hypothetical map had dozens of unit types, many of them targeting each other unpredictably with all sorts of AA attacks, and battles between stacks of 50 happening regularly. But the speed increase is extremely impressive, and even if the AI only used this to simulate smaller battles while keeping the battle calculator for battles that are too large for this algorithm, that's already a massive breakthrough in improving performance.</p>
]]></description><link>https://forums.triplea-game.org/post/37275</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37275</guid><dc:creator><![CDATA[alkexr]]></dc:creator><pubDate>Thu, 07 May 2020 21:03:35 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Thu, 07 May 2020 20:50:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/trevan" aria-label="Profile: Trevan">@<bdi>Trevan</bdi></a> said in <a href="/post/37273">Development Discussion: Speeding up battle calculator (and thus Hard AI)</a>:</p>
<blockquote>
<p dir="auto">MiniMax: 93.5 ms, Win: 0.506233909545216, Lose: 0.38491296598075025<br />
Hard AI 200 runs: 1787.9 ms, Win: 0.47, Lose: 0.435<br />
Hard AI 2000 runs: 1471.6 ms, Win: 0.501953125, Lose: 0.388671875<br />
FastOdds: 6.8 ms, Win: 0.5</p>
</blockquote>
<p dir="auto">How is 200 runs slower than 2000 runs?</p>
]]></description><link>https://forums.triplea-game.org/post/37274</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37274</guid><dc:creator><![CDATA[Cernel]]></dc:creator><pubDate>Thu, 07 May 2020 20:50:57 GMT</pubDate></item><item><title><![CDATA[Reply to Development Discussion: Speeding up battle calculator (and thus Hard AI) on Thu, 07 May 2020 20:47:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/redrum" aria-label="Profile: redrum">@<bdi>redrum</bdi></a> here's the numbers rerun with FastAi's calculator included.</p>
<p dir="auto">1 infantry, 1 armour vs 2 infantry<br />
MiniMax: 93.5 ms, Win: 0.506233909545216, Lose: 0.38491296598075025<br />
Hard AI 200 runs: 1787.9 ms, Win: 0.47, Lose: 0.435<br />
Hard AI 2000 runs: 1471.6 ms, Win: 0.501953125, Lose: 0.388671875<br />
FastOdds: 6.8 ms, Win: 0.5</p>
<p dir="auto">1 armour, 1 tactical_bomber vs 2 infantry, 1 fighter<br />
MiniMax: 2.2 ms, Win: 0.1150459321571266, Lose: 0.7947330200775955<br />
Hard AI 200 runs: 1025.3 ms, Win: 0.085, Lose: 0.91<br />
Hard AI 2000 runs: 1194.6 ms, Win: 0.06640625, Lose: 0.9287109375<br />
FastOdds: 0.5 ms, Win: 0.34082222539412593</p>
<p dir="auto">1 infantry, 1 artillery vs 2 infantry<br />
MiniMax: 2.9 ms, Win: 0.4574200859119973, Lose: 0.45742008591199734<br />
Hard AI 200 runs: 1038.0 ms, Win: 0.465, Lose: 0.405<br />
Hard AI 2000 runs: 1385.9 ms, Win: 0.4521484375, Lose: 0.4619140625<br />
FastOdds: 0.4 ms, Win: 0.5</p>
<p dir="auto">1 cruiser, 1 destroyer vs 1 cruiser, 1 destroyer<br />
MiniMax: 1.6 ms, Win: 0.4250031963247701, Lose: 0.4250031963247701<br />
Hard AI 200 runs: 1047.1 ms, Win: 0.405, Lose: 0.46<br />
Hard AI 2000 runs: 1140.1 ms, Win: 0.412109375, Lose: 0.4345703125<br />
FastOdds: 0.7 ms, Win: 0.5</p>
<p dir="auto">1 cruiser, 1 destroyer, 1 battleship vs 2 cruiser, 1 destroyer<br />
MiniMax: 3.1 ms, Win: 0.5358330747385637, Lose: 0.34400771480746317<br />
Hard AI 200 runs: 1032.0 ms, Win: 0.775, Lose: 0.165<br />
Hard AI 2000 runs: 1141.3 ms, Win: 0.8125, Lose: 0.1328125<br />
FastOdds: 1.6 ms, Win: 0.6591777746058741</p>
<p dir="auto">1 infantry, 1 fighter vs 1 infantry, 1 aa gun<br />
MiniMax: 1.3 ms, Win: 0.6961033280443275, Lose: 0.2000276003717069<br />
Hard AI 200 runs: 1138.5 ms, Win: 0.38, Lose: 0.615<br />
Hard AI 2000 runs: 1248.8 ms, Win: 0.4130859375, Lose: 0.583984375<br />
FastOdds: 0.2 ms, Win: 0.7180577051181194</p>
<p dir="auto">Fast Ai is really fast.  Not sure how to compare the win percentage.</p>
<p dir="auto">I have an idea on how to do multi-hit and AA.  I'm going to attempt it.  I also need to deal with units with multiple rolls.  Is there a map in TestMapGameData that has units like that?</p>
]]></description><link>https://forums.triplea-game.org/post/37273</link><guid isPermaLink="true">https://forums.triplea-game.org/post/37273</guid><dc:creator><![CDATA[Trevan]]></dc:creator><pubDate>Thu, 07 May 2020 20:47:24 GMT</pubDate></item></channel></rss>