1. i just switched it to use countdownlatch, but the point of both is to make sure that the data has been set before we set the settings or start the calc
2. to make sure the data has finished being loaded (because it is in a separate thread) before we do stuff
3. to put it in a separate thread, that way someone with 16 threads doesn't have to wait while the game engine copies the data 16 times. (you will notice i also made the player ui btl calc use our concurrent calc, and i don't want it to 'lag' when they click ctrl-b)
4. i'm not really sure, but i know the other calc uses it
5. edit: i fixed this so that it is a minimum of 1, but will not submit extra threads if we are lower than the number of threads.
6. two reasons, one to name the threads, and two to make them daemon threads
i am pretty excited about this multi-threaded calc!
it really speeds things up
Ok. I think my only concern at this point is the isDataSet and isCalcSet flags. I think it might be better to put a waitForTermination when setting the data to make sure all the threads finish setting data before moving on.
I think this would prevent the situation you are trying to handle using these flags. And would eliminate the possibility of it ever getting to calculate and throwing this:
throw new IllegalStateException("Called calculate before setting data and calculate data!");
That exception will mostly likely screw up the AI calculations so if we can force the data to be copied before moving on that would be better. Let me know what you think.
And yeah performance-wise it is definitely a big win. I'd be interested in seeing some statistics for machines that have 8 threads.
since you can set the data to null, a wait for termination won't help
and since setting the calc settings is not done with an executor thread, waiting for termination won't help with that either
the count down latch handles waiting for the thread to finish
therefore the ONLY way you could possibly encounter the illegal state exception is if you:
1. call calculate before setting the calc data (since both occur on the thread that called them)
2. have different threads call the different methods
Neither of them is possible for you, so the exception is more like a check against stupidity. (that is why it isn't a checked exception)
my 8 thread cpu was completing some calcs in 1/3 of the time it takes without the threaded calc
Testing fun. This is great! Crashed after I was most of way through 1st round with "Hard AI" selected. Hope I am testing right! As a verification, I tried it with medium AI, and no crash. Went back to Hard AI and got same crash. Keep up the great work!
Woot! Redrum, I am sure Veqryn appreciates your efforts immensely as we all do and I'm so excited to see this final part of the Triple A Axis and Allies game finally worked on.
Ok, I hope you appreciate my feedback and find it usefull ...
1st for Veqryn - I noticed late in the game when I purchased tech to help deliver the final blows to the AI that I had successfully rolled 3 6's to get 3 techs BUT IT ONLY GAVE ME TWO TECHS?? When we played the board game version of this game, if you rolled a 6 and already had that tech, then you just re-rolled a die 6 to pick another tech but in YOUR computer game version IT JUST DENIED ME A NEW TECH AND I WAS LIKE UHHH HOW UNFAIR LOL - so is that how you wanted tech to be done? Anyway to have the computer just randomly give you a different tech if you already had the 1 tech if you had rolled more than one 6 to get another tech? Maybe that's what you want but I think if you roll two 6's then you should get two tech's right? Here's the screenshot:
Redrum, so I played your one AI patch (haven't tested the newer patches yet sorry but I will) and I haveto say SUCCESS! I mean the AI played WAY BETTER! I still beat the game in my 2 matches but absolutely for sure the game AI is way improved and I'm sure Veqryn is very excited about the potential of this awesome game finally on the finishing home stretch. I noticed you have a Hard AI, and all this time I thought Dynamix(Land-Only) was the hardest AI but anyways I chose your Hard AI and I think I have always been playing Dynamix(Land-Only) AI all this time and now realized that I shouldn't have played it and should have played the MooreEnabled AI because the Dynamix(Land-Only) really wasn't allowing the AI to have any intelligence with Sea units and so when I played your new Hard AI right away I realized the game AI played the Sea units way more effectively so I learned something there.Will you get rid of Dynamix(Land-Only) AI eventually when the Dynamix AI is both Land and Sea AI? Anyways, so I first tried to battle the Allies being played by the AI on the WWII Classic map so it would be 3 countries versus me playing the 2 Axis countries and right away Russia held Karelia S.S.R. strong and I was actually worried (because I have only 1 loss to the AI in literally 40 or 50 matches) and so I bared down and did smart purchasing and stacked up on Infantry and eventually Germany was strong enough to wear down Russia and I took the Russian capitol in maybe 6 or 7 rounds ... and I noticed the Allies AI was building Sea units way more effectively and I was amazed the Allies AI actually attacked other Sea zones which it rarely did before and I also noticed first time that the American AI actually entered into Africa to help take it over and this was all things I never seen the AI do before until your new AI! So I have a screenshot of that match but I want to show it because my point is the American AI still was up to its old ways and neglected its capitol and it also always builds up in South America and pretty much didn't do much to help the other 2 allied countries all game as usual (I have old screenshots of the American AI literally building up 120 units in South America all game and just sitting there doing nothing) and so again this screen is an example of how your AI still just can't think intuitively .... UNLESS YOU IMPLEMENT MY "LEARNING AI" IDEA.
Ok, so then I played the Allies and had the game AI play the Axis (please note that I always have let the forum know that even with the actual Axis and Allies board game - which I LOVE - we started letting GERMANY GO FIRST. So on the Triple A Axis and Allies game, I buy all the Russian tech dice and won't start the match until all money is wasted on tech and NO tech is achieved and only start the game if Russia has no tech and does NO PURCHASES and NO MOVES because I thought this was more like the real WWII version of events with Germany starting the war so I preferred it and we liked the challenge for the Allies!) and so the game starts with the German AI moving first and again it started strong so ofcourse I only purchased Infantry for Russia and thankfully I kept Germany busy enough with the U.K. and the Americans and eventually took over the German capitol ... although I was fortunate because 1. I stupidly missed a backdoor 3 tank Russian capitol take-over by Germany because I wasn't looking and I should have easily beat the AI in maybe 12 rounds but my mistake allowed Germany to get some extra cash and therefore delayed their defeat by at least 5 or 6 rounds and also 2. JAPAN DID NOTHING. I am going to leave a screenshot so you see how Japan literally just stayed on 1 territory all game AND DID NOTHING. Usually its the American AI that does nothing but, I'll tell you, had the Japan AI did anything this match then perhaps I may not have even won but heres the screenshot so you see again that maybe my idea of a "learning AI" would help make the AI more challenging. Oh, I remember something I noticed in my 1st match against your AI ... early in the match the Russian AI came out strong BUT what I noticed was instead of concentrating ONLY on Karelia S.S.R. which immensely helps the Allies, your game AI evenly split itself into the 2 territories of Karelia S.S.R. and the Ukraine S.S.R. instead and this was the most significant reason why I could takeover the important Karelia S.S.R. and eventually defeat the Russian AI capitol. So you see? A learning AI would know which territories are important and your AI spread the armies too much so maybe you can think about that and improve that one aspect but overall I saw a huge improvement in the AI so, so far so good but here is the screenshot for the Japanese AI which clearly shows something still needs improving;
Lastly, I actually thought of a thread I found on the internet about memory allocation for games and this was for a super huge game called Dungeons and Dragons Online - I still havent read the entire thread - but it made me think of your guys discussion about memory allocation and so I thought perhaps there could be something useful for you guys!;
douglyfresh - Great to see some people are starting to test the new AI out. I opened the save and it definitely immediately occurs again. Looks like the exception occurs when simulating battles using the new concurrent battle calculator. I'm not exactly sure why its happening since it is occurring in the DiceRoll delegate which I'm not very familiar with. I'm hoping Veq will take a look and shed some light on it as he is more familiar with this code.
Glad to see your enjoying the new AI. The part that has been rewritten so far is the combat move AI. The remaining phases are based on the Moore AI (now medium AI). I don't recommend ever playing against the dynamix AI as it is incomplete.
Unfortunately, the non-combat move AI hasn't be rewritten yet so it will still do many dumb things such as not protecting its capital and moving units to areas that don't need them such as Brazil. So I'm not too concerned with the USA screenshot right now.
On the other hand, the Japan one is definitely a big issue as it should attack with those units across Asia. If you can submit your save game for this I would really like to take a look. I'm guessing some error is occurring that is causing it not to make any attack moves and this is definitely a bug.
Oh sorry I didn't save the game but it may not be a glitch because that screenshot doesn't show I had tons more units on my Allied side than the Axis played by the AI and I had Germany captured so I think overall Japan was alone and outnumbered to the point where it couldn't stray from it's capitol. The AI as Japan was not very aggressive at all while Germany was defending for about 15 rounds and remember Germany grabbed my Russian capitol for 1 round by my mistake so Japan had no need perhaps to move towards Europe and also in the screenshot you see late in the game Russia grabbed back its territories but ya the AI was indecisive and stalled as you can see so I wanted to show you so you can see where the AI is currently at.
No one said this was gonna be easy eh but good luck I love having the matches to test it out quite fun.
A "Victorscapturedterritories" file would help but I know yous are working on the first step basic logic for the AI which needs to be done and then can run on any map. I still see the light at the end of the tunnel for this awesome game!
I am most happy to game test. You and Veqryn are doing the heavy lifting. I noticed the Moore version seemed to be quite random (in a bad way) with implementing political decisions on the game I tested. I might try testing without the politics for now.
so i did some debugging and figured out what was happening with that error
the error is occurring because you are somehow sending duplicate units into the battle calc for Malta
Duplicate Units Detected:
Original List:[bomber owned by Italians, armour owned by Italians, infantry owned by Italians, armour owned by Italians, infantry owned by Italians, armour owned by Italians, infantry owned by Italians]
HashSet:[infantry owned by Italians, bomber owned by Italians, armour owned by Italians, armour owned by Italians, infantry owned by Italians]
As you can see, you have sent 7 units, but only 5 of them are real (you have 1 of the infantry twice, and one of the armor twice).
i added checks for duplicate units to all places where we roll for units, so that we won't get cryptic errors about array-out-of-bounds
i also removed your try-catch in the ai, since it is unneeded (the error should bubble up instead of being caught)
i saw you changed to hashset, which will at least stop the bug from occurring
but i am wondering, did you figure out the root cause of why the AI thought it could move units to attack twice, or w/e?
also, i see that your minimum % to win is 95%
this seems really high, as there are plenty of situations where i would attack at 75% or even 50%, depending on the results of combat, the territory and position, etc etc
edit: for anyone who wants to test the new version of the AI, please go here and download the jar file, and then copy it over top of the old jar file in your install directory (/bin/ folder)
OOk, the new AI is for sure much better and very close to being acceptable. Here is my last 2 matches against the new AI.jar from the link in the post above this:
1st I played as the Axis and defeated the computer AI playing the 3 Allied powers and I defeated the Allies easy in about 10 rounds and never had any trouble at all.
Then 2nd match I played as the Allies and forfeited my very 1st turn as Russia (just as a little more challenge as I told yous I do) and the AI playing the Axis did put up quite a battle and perhaps my longest game ever went 30 or so rounds for me to finally beat the Axis. I took a screenshot to show you how the AI had left a "backdoor" weakness with its German capitol around the 5th round where I had maybe 1 or 2 more units to go in with than the German capitol had and was lucky to capture Germany, and that momentary capture helped me ofcourse but Germany took back its capitol and I just wonder if it hadn't left its capitol weak there that perhaps the AI would have finally beaten me again who knows because the AI played tough all game with strong purchasing - seems like the best combo for any competitor in this game - human or AI - is load up on infantry and having a strong airforce in my opinion. Oh the Japanese AI (I mean the overall AI I guess) was much better aggressively and whatever you tweaked helped I am quite sure. Whats funny is the AI as the Axis did obtain an "Economic Victory" I think around 9th or 10th round thanks to Japan .... which was impressive but that reminds me .... playing as a human player, sometimes I'll capture both Axis countries and have almost every single territory but it still won't give me an "Economic Victory"?
Anyways, here's where the German AI was spread out and allowed me to capture its capitol for 1 round.
First of all, very good work, after I gave up on ai completely, I think there is hope now, even more it is exciting.
Did Feudal Japan 2 map, cause of your good ai and the results are incredible. Sure ai gets some unit boni, but it provided a very good challenge for me up to round 20, when I finally got better than all other ai players.
One thing to note is: There is a unit with firtstrikes (AA) attack and defense, like this:
so, it does roll at 6 prior to all other units (D12 used here of course) each round of battle on attack and defense, the standard attack/defense values can be ignored, as they will be removed in combat later, by support, this is just for preselecting casualties.
Compared to a unit with only standard attack/defense it is probably worth 9/9, cause standard attack/defense units might get killed before they get a chance to roll at all.
The ai ignores these units completely, does not buy or move them, probably because AA stuff is of minor importance in standard maps.
Question is: Will it stay like this, be ignored completly? If so, no problem, then unit stats just have to changed for ai phases.
Next question: Does ai take support into account at all? For calculation of battles, yes, when using BC, but for purchase decisions?
Next question: What are the things ai takes into consideration? For example, isVictoryCity and isCapital is taken into consideration I think, what else, especially unitattachments? Like isArtillery, isMarine, isSub...
Would be interesting to know, cause then it would be much easier to help ai with purchase decisions, i. e. a unit could get "isArtillery", even if it does nothing, but ai prefers those...seems a good and easy way to make it buy certain units.
There needs to be some logic added when finding the max amphibious units that can attack a territory to not select units that have already been selected by another transport. This occurs pretty rarely so I just added HashSet to eliminate the errors for now.
The min win percentage is mostly a starting point as there are some cases it allows less than that win percentage on attacks. In general though, the win percentage currently needs to be high for the AI otherwise they need to consider possibly losing battles when calculating counter attacks which makes things difficult. For example, if I attack territories A, B, and C with win percentages of 60%, 60%, and 99%. When I calculate possible enemy counter attacks, I'd need to consider if I won A/B/C, won just A/C, just won B/C, and just won C. The only alternative is to consider the worst case scenario and just calculate counter attacks based on winning C. Eventually, I'd like to add more logic like this but wanted to get it working pretty well first before getting to complex.
Glad to see that the AI is putting up a better fight. I'm still working on improving non-combat move and unit purchase AI which should help the AI protect its capital better and remove situations where it leaves things open.
Good to hear that you're are seeing improvements in the AI. The AI definitely does not consider that unit properly right now. I believe it would just ignore the attackAA as it doesn't currently take into account "typeAA" or "targetsAA" so always considers AA attack as defense against planes. It should still attack with it though since it has an attack value of 6 and can move during combat (do you have any saves where you see it not attack with this type of unit?) In terms of purchasing, I still need to rewrite most of the unit purchasing code but I'm pretty sure the current unit purchase logic doesn't take many of those stats into account and probably undervalues that unit.
I would eventually like to add logic to value units like this that takes into account these different attributes such as typeAA, targetsAA, and attackAA but this would probably be after I rework all AI phases to do well on the more standard unit sets. If you have ideas on algorithms on how to analyze the various unit attributes when considering attack, defense, and purchasing, I'd be interested in hearing them. The alternative is to add some AI values to all units per map that give AI values for the various phases such as attackAI, defenseAI, purchaseAI, etc but again this would take a lot of work since we'd need have separate config for all maps.
When attacking it does take into account support but I haven't rewritten the purchase yet so it probably doesn't consider it when purchasing.
For purchasing, it still uses the old MooreAI algorithm which is pretty random and I don't think it takes into account any of those. For combatMove, it considers many factors when choosing what territories to attack (production value, isCapital, has unit that can be captured, TUV swing, etc) and considers mostly just attack/defense/AA/support/hp when choosing units to attack with. I wouldn't recommend adding random attributes such as isArtillery as that will just clutter your unit config and the AI shouldn't value random attributes if they have no value.
This is a bit late, but I played the patch from I think it was Mar 24 or 27 (jar file doesn't say which one it is) and I keep seeing this loop which has to be a bug. Notice in the pic how the US continues to dump troops into N. Africa along with tons of transports but never attacks Spain. It could overrun all of Europe in 2 moves but keeps stacking:
This is a common theme I notice the Japs stack transports but have no armies, in the WWI map the US and allies coming from America get stuck in this loop. And in WWII maps the Canadians will stack troops but no transports.
Also, the way nations attack from the sea is still not helpful. For instance Japan or England will invade a territory by sea with 2 troops even though the surrounding territory will crush them. There's never a consolidated build up or coordinated effort for this to lead to any objective other then to hit easy territory.
Hey tgla, glad to see you are testing out the new AI. Do you have any save games that you could upload that have some of the odd behavior you describe? This would help much more than descriptions or pictures since I can then test them myself and see why the AI isn't attacking. I'm also not familiar with that map from the picture you uploaded, which one is that?