Development Discussion: Speeding up battle calculator (and thus Hard AI)
-
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.
MiniMax: 197.7 ms, Win: 0.5520100874509435, Lose: 0.40334641519178716
Hard AI 200 runs: 2025.6 ms, Win: 0.57, Lose: 0.42
Hard AI 2000 runs: 3222.8 ms, Win: 0.5517578125, Lose: 0.412109375
FastOdds: 7.9 ms, Win: 0.7703534497836491, Lose: 0.0Now I'll work on multi-hit units.
-
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.
-
@redrum @RoiEX
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: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.0All 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.
What would you like me to do now? Can I make this available to others (such @Swampy) so they can test it out?
-
I'm not 100% sure what @redrum's opinion on this is, but I'd really like to see this as an experimental Ai in the game.
But for now hide it behind the test flag? -
Perhaps it could be added as a checkbox in the battle calculator for now as well?
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?
-
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.
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...)
-
@RoiEX I'm not aware of the test flag. How do I use it?
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. @Alexei-Svitkine 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?
-
if(ClientSetting.showBetaFeatures.isSet()) { // add experimental feature } -
@LaFayette I tried using that in the PlayerType enum
BATTLE_TREE_AI("BattleTree (AI)", ClientSetting.showBetaFeatures.isSet()) { @Override public Player newPlayerWithName(final String name) { return new BattleTreeAi(name); } },But the player is still showing up in the list.
I also tried:
BATTLE_TREE_AI("BattleTree (AI)") { @Override public Player newPlayerWithName(final String name) { if (ClientSetting.showBetaFeatures.isSet()) { return new BattleTreeAi(name); } } }, -
@Trevan
Looks like @LaFayette trolled you a little bit there.
TryBATTLE_TREE_AI("BattleTree (AI)", ClientSetting.showBetaFeatures.getValue().orElse(false)) { @Override public Player newPlayerWithName(final String name) { return new BattleTreeAi(name); } },instead
-
@RoiEX That worked. I have to restart triplea for it to affect.
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
Failed to start game IllegalArgumentExeption: File must exist at path: /.../game-headed/assets/unit_scroller/unit_sleep.pngI'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.
Is there something I'm missing?
And should I create a PR now?
-
@Trevan are you using a specific IDE?
I think you have to run
./gradlew downloadAssetsbefore running the game in order to download all the default assets -
@RoiEX I'm using IntelliJ
-
And yes, you can create a PR whenever you like, it will take us a while to review it though
-
@Trevan If you're using intelliJ then it should automatically download the assets.
Try deleting theassetsand.assetsfolder and it should force a re-download -
@RoiEX 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
game-headed/assets/unit_scrollerso things have been downloaded. -
@RoiEX deleting the
assetsand.assetsfixed the issue. -
I've created a PR - https://github.com/triplea-game/triplea/pull/6501
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login