As a French person I feel like it's my duty to explain strikes to you. - AdrienIer

Create an account  

 
Caster of Magic II Brainstorming Megathread

Both types of stackbuilding can draw units from the field as well as cities.
Reply

(April 17th, 2020, 14:01)Seravy Wrote: Both types of stackbuilding can draw units from the field as well as cities.

Yes but, according to your last post, summoning always goes to garrison. Or did I understand that wrong? So there's no way to summon for a field stack, it has to go to garrison duty first, then another algorithm that draws troops out of garrison brings them to the field. There isn't even a priority sequence between different towns.

That's why the player can abuse minimum threshold. If the AI has to summon for a garrison at complete random before it runs the field stack algorithm, then they would summon to the same city over and over unless another city fell further below the threshold. 

If there was a way to determine a priority sequence, this would be a meaningful question. As it is, I think it really doesn't matter what the percentages are, except maybe Fortress if filling up to 9 sooner is better -- but it isn't, in the early game. The net effect is which ever has the bigger percentage fills up faster, but there's no way to judge whether that's good or bad without game situation context.
Reply

Quote:Yes but, according to your last post, summoning always goes to garrison. Or did I understand that wrong? So there's no way to summon for a field stack, it has to go to garrison duty first, then another algorithm that draws troops out of garrison brings them to the field. There isn't even a priority sequence between different towns.
Correct. Typically, summoned creatures stay in the city until the stackbuilding function draws them out because they are too high value to get sent out as part of the "over9unitsontile" function automatically, which is the one responsible to make sure the units less good at garrisoning become the field units.

... this worries me actually considering multiple stacks are built at a time because it means units will always get drafted from cities (unless there are less than 9 cities on the continent) as long as they have 9 units, before the over9units function gets used, so garrison quality will not automatically increase. When building only one stack at a time, this wasn't a problem because unit production was much faster than the rate they got pulled into new stacks. We might need to come up with a way to prevent this.

Quote:The net effect is which ever has the bigger percentage fills up faster, but there's no way to judge whether that's good or bad without game situation context.

Yes, that's pretty much the question we need to answer. Which do we want the AI the to fill up faster, if any :
-The fortress garrison
-The forces on the frontier continent (which will be able to actually leave the city as a stack once that gets added)
-garrisons everywhere else

We do know the game situation context, in the sense if we don't want a constant priority, we can calculate it from from game variables - question is, do we want that, and if yes, what do we want to base it on. We could, for example, say the AI has to summon more at their fortress if they are maniacal, or if the enemy has a military advantage on the historian.

Successfully implemented the AI stackbuilding functions meanwhile. It's shockingly efficient compared to the original - although only tested it with a small map and few units so far, it's crazy to see the AI build two stacks of 9 nagas (or land troops) simultaneously in only 2-3 turns. I don't think we need to worry about the stackbuilding itself, which means the decision where to summon will play a greater role in how much doomstacks the AI has. (Frontier city and Fortress both lead to doomstacks because the units appear at one place. Garrison summoning does not, unless the cities are already filled up the mandatory requirements and there are at least 9 cities in a range of 20.
Reply

(April 17th, 2020, 16:27)Seravy Wrote: Successfully implemented the AI stackbuilding functions meanwhile. It's shockingly efficient compared to the original - although only tested it with a small map and few units so far, it's crazy to see the AI build two stacks of 9 nagas (or land troops) simultaneously in only 2-3 turns. I don't think we need to worry about the stackbuilding itself, which means the decision where to summon will play a greater role in how much doomstacks the AI has. (Frontier city and Fortress both lead to doomstacks because the units appear at one place. Garrison summoning does not, unless the cities are already filled up the mandatory requirements and there are at least 9 cities in a range of 20.

That's wonderful. I'm looking forward to playing against the improved AI stackbuilding capabilities. Seeing the vast amount of un-stacked units covering the map late game pointlessly has really gotten to become a pet peeve of sorts.

With regards to using game variables to determine the percentages, I think it's certainly preferable, but I don't think only a few variables would be meaningfully different from a constant priority. We'd need enough variables to establish some kind of priority sequence of things to do. The essential issue is that unlike the human, who looks at the map and says "what's the plan" --> "what unit do I need" --> "where do I need it" --> "summon there", the AI goes "roll a spell" --> "roll a unit" --> "roll summon locations" --> "build stack" --> "decide stack targeting plan". The "what to do" is at the end instead of at the beginning of the decision process.

It's kind of a reversed process. The challenge is to somehow make this "roll summon location" behave in a way that results in something at the end of the "decide stack targeting plan" part that is roughly comparable to what the human would have done in the sense of being a good opponent, keeping in mind how the rest of the chain works. And that's potentially very difficult.

This is just a sample of the variables that might need to be considered:
  • The strength of available normal units that can be built. Stronger units should usually mean a preference for frontier summons, to gather more offensive troops closer to the enemy, as you can rely on normal units for garrisons
  • How strong a garrison is relative to the city's importance, as measured by available unit production, building value, and the distance from potentially hostile units (ie, the closer potentially hostile/neutral units are and the stronger they are, the stronger the garrison required, and the more valuable the city, the stronger the garrison required; and this increases priority for summoning the weaker the garrison actually is. A gap of 5 units for example, is more severe and pressing than a gap of 1 unit, but if it's "hopeless" and can't summon enough in time, then priority also drops.
  • The win/loss ratio of previous battles. The higher the loss ratio, the greater the preference for fortress summons (it builds doomstacks, but is more of a defensive measure at the center of the empire, allowing the units more time and turns to summon more before regathering into doomstack. Basically, the idea is to use the loss ratio as a way to help the AI "learn" and stop sending more stacks to die in offensive operations), and garrisons everywhere. Even better if different ratios could be calculated on types of attacks, and how the actual win/loss varied from the overland strength calculation/the pre-combat simulation--so the AI responds to lost towns by increasing garrison strength. This can work for offensive stacks and targeting too. The more the AI loses, the higher the stack strength advantage needed before attacking again.
  • How many times a city has already been attacked, or battles fought in its vicinity recently. The more fighting, the more summons needed nearby.
  • The value-strength differential of enemy/neutral cities. The existence of underdefended valuable cities should cause the AI to summon more nearby to build stack and attack opportunistically.
  • Has any wizard tried to attack a fortress, and how many times it happened. The more such attacks, regardless of success or failure, should cause the AI to prefer fortress summons, with the preference disappearing over time if no further attacks happen.
Some of the above only work if the AI could choose the individual city, not just the overall three options. If that can't be done, a simple way to get decent outcomes could be to use the military rating to owned cities ratios for each wizard (let's call this the militarization ratio), modified further by hostility/friendliness, further calculated relative to the AI's own ratio. The basic ratio would estimate how "well covered" the overall garrisoning is for a particular wizard, then taking that relative to the turn AI would estimate how much the AI needs to prioritize defense vs. offense.

Essentially, the bigger the militarization ratio of any unfriendly wizards compared to the turn AI's militarization ratio, the more they prefer defense because it's easier to defend than to attack (combat advantage and movement), thus preferring Fortress and garrison instead of frontier. Conversely, the lower the enemy ratio and the bigger the relative ratio, the more they prefer frontier summoning and building doomstacks to attack.

It's inaccurate to take only the militarization ratio on its own, because "normal" militarization ratio could change over time, as wizards gain global spells and more powerful stuff that don't proportionally cost more, gain hordes of undead, etc.
-
Reply

Quote:It's kind of a reversed process. The challenge is to somehow make this "roll summon location" behave in a way that results in something at the end of the "decide stack targeting plan" part that is roughly comparable to what the human would have done in the sense of being a good opponent, keeping in mind how the rest of the chain works. And that's potentially very difficult.

The AI's plan is "let's do everything at the same time". Partially because it cannot corretly judge what's the best move but even more because playing a well defined and predictable strategy means it's easier to counter. There is also enjoyment to consider, the AI has to do some stuff not because they are efficient but because they are necessary for the game to feel like a game, garrisoning being a prime example. Even if not garrisoning would be more efficient (it probably isn't due to the risks), the AI has to garrison cities well anyway otherwise conquering them is too is easy and that's not fun.
So this reversed process works very well, as long as the "do everything" is properly weighted to do the better things more often.

Quote:Essentially, the bigger the militarization ratio of any unfriendly wizards compared to the turn AI's militarization ratio, the more they prefer defense because it's easier to defend than to attack (combat advantage and movement), thus preferring Fortress and garrison instead of frontier. Conversely, the lower the enemy ratio and the bigger the relative ratio, the more they prefer frontier summoning and building doomstacks to attack.

This is actually fairly easy to use and seems to provide the best overall information.
In fact the AI already has a "more units needed" flag and a "much more units needed" flag which are turned on by the human player exceeding equal, or double the AI's total historian military.
So basically, we could make it so that when the flag(s) are on, increase the chance of garrison (or fortress? or both?) summoning by one.

Another thing we might be able to use is the total number of cities owned : the more cities the AI has, the more they need to summon for garrison to have the same amount of defenders.

But now that I stop for a moment, these two (partially) contradict. More cities means the AI will have a stronger military so they'll prefer to attack more, but they also have more they need to defend.

In fact this is a core contradiction, not specific for this feature but the entire game overall :
The more territory you have, the more likely it is to be able to win through holding that territory, but it also makes it easier to expand further, as more territory leads to a resource and military advantage. Meanwhile less territory means you are going to lose if you don't expand, but you don't have the tools to expand either.
So...in either case it doesn't actually matter which of the two the AI chooses, a larger/stronger empire means more success for both offense and defense as a strategy, it doesn't specifically help either more than the other.

So I'm actually starting to doubt this even matters. If the AI is leading, whatever they do works. If they aren't, whatever they do will not help anyway. So maybe the main thing to consider is what's more fun? If the AI only stays on the defense that's boring but if they spam doomstacks and leave everything poorly defended that's even worse. So maybe the equal ratio is good? Hard to tell.

That said, the idea to summon (or simply build) more units in a city on the same continent as, and close to a poorly defended enemy city is not bad. Except, the city on the continent with the most enemy cities - which has the highest probability to have something undefended, or more importantly, allows a single AI stack the threaten the most number of cities simultaneously, forcing the player to build the most garrisons until they kill the stack - so that city is already the one chosen as the frontier city, and also the one with higher priority to spend gold and build units.
So this actually is already covered in the current system indirectly. This would only really do something different if the enemy city was at close distance but on a different continent, which isn't the main action continent despite the low distance and presence of an easy target, and the summons are guaranteed to be flying/swimming. That's probably too unlikely to be worth adding it.
Reply

(April 17th, 2020, 19:47)Seravy Wrote: Another thing we might be able to use is the total number of cities owned : the more cities the AI has, the more they need to summon for garrison to have the same amount of defenders.

But now that I stop for a moment, these two (partially) contradict. More cities means the AI will have a stronger military so they'll prefer to attack more, but they also have more they need to defend.

In fact this is a core contradiction, not specific for this feature but the entire game overall :
The more territory you have, the more likely it is to be able to win through holding that territory, but it also makes it easier to expand further, as more territory leads to a resource and military advantage. Meanwhile less territory means you are going to lose if you don't expand, but you don't have the tools to expand either.
So...in either case it doesn't actually matter which of the two the AI chooses, a larger/stronger empire means more success for both offense and defense as a strategy, it doesn't specifically help either more than the other.

So I'm actually starting to doubt this even matters. If the AI is leading, whatever they do works. If they aren't, whatever they do will not help anyway. So maybe the main thing to consider is what's more fun? If the AI only stays on the defense that's boring but if they spam doomstacks and leave everything poorly defended that's even worse. So maybe the equal ratio is good? Hard to tell.

The contradiction only exists if you use the direct military rating (either the historian or int. agent). By using the militarization ratio as I defined above which considers how well covered the empire is, it allows the AI to distinguish between conditions that are favourable for offense as opposed to the need for more defenses.

For example, if you have more cities, your overall historian rating is higher. But you also need more troops to defend it. If you have 100% "coverage", you are adequately defending all parts of the empire. You can then use the excess for offense. But would you want to attack if your opponent has an even bigger excess than you? Even if they're technically smaller, if they are more militarized, they might well have more troops to fight you with. If it's fighting on two fronts, or three fronts, this could help the AI judge when it has the ability to take on both opponents at the same time and expect to win, and affect the willing to peace or not.

Plus, there's the active management of overextension. Each time you conquer territory, you need to actually hold it for it to have value. You won't snowball if you lose it just as easily by not having enough forces to cover the new territory. The militarization ratio will drop every time you conquer a new city, as the denominator increases and numerator either stays the same (no combat losses), or decreases. Thus, the AI learns to hold and reinforce its new territory.

It is not always true that more territory = stronger. Because of racial differences, non-city sources of Power, and personality focuses, it's quite possible to have lopsided militarization ratios. This will hopefully allow the strong military focused AIs to organize offense and identify opportunities better, while making the more economy focused AI to play better at defending themselves.
Reply

Oh, I understand. Sorry, I missed the part that militarization ratio is military/number of cities.
So you also suggested more cities=need more garrisons.

But I disagree that militarization ratio between players should be compared - military ratio should.
If I have 2 cities and 8 value troops, but the enemy has 8 cities with 2 value troops each, my militarization ratio will be 4 and theirs will be 2.
Nonetheless, attacking them would be a suicide and I should focus on defense anyway because my absolute military value is 8 and theirs is 16. Sure I might be able to conquer a city but I can't hold it for long and I also can't go any further.
Absolute military value is used by the AI in every single diplomacy decision where military is considered anyway and diplomacy determines whether the AI will be able to be enemies with that player or not.

Except, that's still for normal units and we are talking about summoning outstanding doomstack (or doomstack stopping) quality units. Ok, let's try to model this properly.
This is basically a game where you have to divide X units into two piles -attacker and defender - and the enemy does the same with their Y units.
If both your piles are bigger than the enemy matching piles (your attack vs their defense and the opposite) you have chosen the correct strategy and win. If both your piles are smaller, you lose. If one is bigger but the other is smaller, then you win if the difference in your favor in larger.

If X>Y then you cannot possibly lose both piles. You can win both piles, or win one. If you win one but lose the other, the difference in your favor will be larger (it is always X-Y regardless of how you divide the units).
Likewise if Y<X then you will always lose, regardless of how you position the units.

So...ultimately it doesn't matter where the units are, at all. The person with more summoned unit wins, regardless of where and how they are used, assuming they are the only relevant units capable of killing each other.

Which isn't true. Normal units will likely not kill much and even if they do normal units do compete with summoning in the sense you have to pay the same resources (gold and production) as you do for buildings that increase your summoning capacity so basically, you can pretend any normal troops used for this is "could have been a summoned creature if I built an amplifying tower instead".
But that still leaves one more thing. Units are also killed by combat spells and defender advantages.
Which means the answer to our question is as simple as "which is more efficient, using 1-3 units with defensive advantages, or using 9 of them without defensive advantages as a domstack" and what changes this?


The answer? Well, if there is an ongoing war (or hostility) then the 9 stack is usually more efficient, as it can win the fight quickly, not allowing a significant amount of spellcasting. If there is no ongoing war, then the defending units are better because in case we get attacked unexpectedly, the defending units will be instantly relevant, but the 9 stack won't be - it has to reach enemy territory first.

And that's exactly what isn't going to work. Why? Because the AI won't be able to build up the 9 stack during an ongoing war. The war being ongoing means the units on their way to meet will be killed one at a time, not really being able to build the stack most of the time. Frontier summoning might be an exception to this though- after we implement it - as that gathers the units inside a city and the stack doesn't leave unless it's complete.
So I suspect, the answer we have been looking for might be "raise priority of frontier city during an ongoing war (or hostility) with the human player, if the frontier city is near the human player's cities, otherwise doesn't matter."
We could replace "human player" there with "any other player", but shouldn't, as both AIs focusing on their offense and successfully pushing their doomstacks forward will lead to neither agreeing to peace and them destroying each other's empire without really gaining anything, stalling both AI players for the rest of the game. In general the desired outcome in AI wars is to either have one side dominate and win quickly, eliminating the other, or if they are nearly equal in strength, have the fights die out and a peace treaty form after field units were killed, and prioritizing offensive summoning works against that.
Reply

But the summoning decision isn't about diplomacy. It's about optimizing unit positioning. The decision to actually wage war or not can be kept separate. So in absolute military terms, the 2 city wizard isn't going to declare war on the 8 city one if they have half the overall military.

If the 2-city wizard gets attacked, then focusing on defense is a definite losing proposition, because the enemy's production rate is higher. Passive defending would be the suicidal course. Attacking at least has a chance of succeeding if something external changes the situation, especially if both sides already have near full garrisons. The excess troops the 2-city wizard has would just be sitting there doing nothing and costing maintenance. That's why it makes sense to establish more doomstacks and be in position to attack, if the enemy shows any weaknesses/gets attacked by someone else, or just plain has really bad positioning. Even if they don't actually attack, for defensive purposes, it's better for the stacks to start at the border, then as they lose militarization ratio because of losses, shift summoning towards the centre.

Essentially, the militarization ratio based summoning allows the AI to overcome the exact problem you talk about at the end. They need to prepare those stacks before the war actually starts.

But where this really makes a difference is when two AIs have roughly similar overall power, but very different military focuses. If they have the same number of cities, but different military ratings, we can let the diplomacy work normally, but use the militarization ratio comparison to help the weaker military one optimize by focusing defense instead of offense and vice versa. The result is letting the AI playing their existing focus/personality/race strategy a bit more effectively.

Both AI players can't push their doomstacks forward if you use relative militarization ratios between the two, unless they have the same militarization ratio. They also can't stall because the ratio changes whenever combat or conquest happens.

Whoever conquers territory will end up having the new territory marked as frontier, the doomstack stays there while the AI's lower militarization ratio makes them reinforce garrisons everywhere consolidating their position, until all is full and they start summoning at the frontier again. Unless their relative militarization is still higher, in which case it makes sense to continue the offensive.
Reply

Quote:If the 2-city wizard gets attacked, then focusing on defense is a definite losing proposition, because the enemy's production rate is higher. Passive defending would be the suicidal course. Attacking at least has a chance of succeeding if something external changes the situation, especially if both sides already have near full garrisons.

That's actually true. But prioritizing the frontier city higher during war (with the human player) if the frontier city has more nearby (human) enemy cities, does cover this situation fully.
(in fact I already changed frontier continent selection to prioritize human cities higher during a war with the human but maybe this should be more detailed. Other AI's don't attack for "hey but this is my continent, I won't tolerate your city here" only the human does, so it should be higher priority to the human player, and for war opponents both, separately and cumulative.)
It also weeds out the scenario when the frontier city is not on the continent of the "8 city wizard".

In case of two AIs fighting though, we do want the 2 city AI to get conquered by the 8 city AI, unless they can maintain peace (in which case the troops don't matter). It won't ever be successful at becoming a relevant threat from that much disadvantage and it'll result in a more consistent overall AI performance if the stronger one wins.

Quote:They need to prepare those stacks before the war actually starts.
Except, the war might not be coming. The AI can't predict that. If the war is not coming, but war with a different person does, the troops will server better in the garrison than on a remote continent in the opposite direction.

Quote:Whoever conquers territory will end up having the new territory marked as frontier, the doomstack stays there while the AI's lower militarization ratio makes them reinforce garrisons everywhere consolidating their position, until all is full and they start summoning at the frontier again. Unless their relative militarization is still higher, in which case it makes sense to continue the offensive.

I don't see the connection. Example. The AI has a militarization ratio of 150 - they have 500 swordsmen (120) and 20 doom bats (30).  This yields 150% priority for summoning at the frontier. Now they conquer a new city. Their city count goes from 10 to 11, so their ratio drops to 136. (now dividing by 11 instead of 10). Still summoning more at the frontier. Let's say they gain 5 more cities. Now the ratio is only 93 so they summon 7% less frontier units than garrison. Yes, that does slow down how many units they summon at the frontier a little but that's not doing much.
Also, the attacking doomstack won't die. So it can keep moving to the next city even without summoning anything new there at which point no formula of summoning priority will have any effect. It is only getting stuck if at least one unit died but a doomstack is often strong enough to not lose a unit to most garrisons. What does have effect is, not summoning the doomstack in the first place - garrison units won't keep conquering, destroying buildings and expanding the duration of the war.

Quote:Both AI players can't push their doomstacks forward if you use relative militarization ratios between the two, unless they have the same militarization ratio.
This is where it goes wrong. You make a connection where there isn't one. Militarization ratio raises or lowers the chance to summon more units into the frontier according to your suggestion. It neither eliminates this chance completely, nor will any doomstacks already there stop conquering. We didn't specify a rule that says the doomstack can't keep going if the AI has poorly defended cities, we defined the reverse, "when the doomstack leaves, that results in a new poorly defended city". but the doomstack has to leave -if it had no losses - because keeping the 9 sky drakes in the newly conquered city for any reason is inefficient and a very bad move. If it leaves, it'll both threaten additional cities and is in a position to retake the city in case the enemy attacks it. If it stays, it simply does nothing, and might even eat more in maintenance than the city is worth - unlike a "normal" garrison of 1-3 Sky Drakes and 6-8 magicians, the maintenance of 9 Sky Drakes is relevant even for the AI.

One other problem with this militarization ratio is that it's vague. Ok, you have to compare yours to someone else's but who is that someone? There can be any number of other players we are hostile towards and any subset of those can be on the "frontier continent" as well and this frontier continent is changing fairly often.

I still think the most direct and effective approach is to tell the AI to summon more if the frontier city is on the human player's continent and they are at war with the human player.
In other cases the only thing I can think of where offensive stack summoning is directly useful for the AI as well as the game as a whole would be if the frontier city is at a place with many lairs and nodes but I doubt the AI really should prioritize that over their garrisoning. Treasure isn't all that important for the AI, they have enough gold and mana and they aren't good at using items and heroes. Only the spells, books and nodes are really useful for them but the former are rare to find and the latter the AI has poor chances to defend on a remove continent with no free field units to leave on the node afterwards.
Reply

Nothing says that the change in summon chances has to vary linearly with militarization. We've only talked about the general concept, not the specific formula. You can have a stepwise function or cubic/exponential one instead. So that when self-to-enemy relative militarization ratio is greater than 1, summon chance rises very fast to 100% frontier.

When I say that both cannot push their doomstacks forward, I mean that they will not be both trying to summon more to frontier to form more doomstacks. Because it's a relative ratio, one must be lower and the other higher, except when they're the same, but that normally won't last for long. The higher one will therefore be pushing all new stacks forward as fast as possible, while the lower one might push any existing stacks forward, but it would hold back summons from frontier and form new stacks farther from frontier, which would be stronger because they have more time to summon and reform before they reach frontier and must battle.

I left relative militarization ratio vague because this was an alternative solution. The other one which uses a more complex system of variables is preferred. However, if we do use relative militarization ratio, it can be defined as follows:

Let M = militarization ratio

Peacetime Relative Militarization Ratio = turnAI.M / Average of AllHostileWizards.M where all hostile is defined as any Wizard with less than Relaxed as the relation excluding Peaceful and Lawful wizards, and always includes human.

Wartime Relative Militarization Ratio = turnAI.M / Sum of All AllWarWizards.M where all war is everyone at war with turn wizard.

Wartime uses sum instead of average because when you're at war on two fronts, you usually don't want to summon new units to frontier piecemeal, better to summon at the centre of the empire and have more powerful stacks that can then decide which direction to go in, unless your militarization is so high it doesn't matter because you've got enough to cover both sides.

Finally, it's important to note that this doesn't directly cause the AI to summon offensive stacks. As I said, this is about unit positioning, when you consider the other parts of the decision chain.

Because you've implemented the new stack formation algorithm, all units will be forming into stacks everywhere at close ranges, and can reform based on updating strengths and new units. The targeting algorithm hasn't changed yet. The garrison algorithm hasn't changed either, but all stacks have to draw from garrisons, and we still have that other problem of garrison quality not increasing automatically.

In general, what should happen is whenever the AI summons to not-frontier, it will only actually stay for garrison duty if there are under-garrisoned cities based on the "required garrison" algorithm. Otherwise, summoning farther from frontier has the effect of giving the unit more time before it reaches the hot zone of fighting, so it has more opportunities to form into a stronger stack as it moves out from empire-center to frontier.

As for garrison quality issue, I don't know how "required garrison" is calculated yet, but one possible way of doing it is to clone and adjust the current field stack building algorithm and run it centered on each city, so garrisons always have the most powerful units, before the field algorithm runs, excluding all the units chosen for garrison.
Reply



Forum Jump: