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

Create an account  

 
Getting a quick combat results calculation

Hi,

I would like to suggest and get suggestions about a quick combat results calculation for the AI and perhaps also for the game quick combat suggestion/execution for the player.
So here is my partial suggestion:

let's take a simple example:
two sides A,B no special or range abilities no spell points only 1 figure

let:
dmgPot = damage potential
defPot = defense potential
HP = hit points

AdmgPot = Aattack*Atohit
BdmgPot = Battack*Btohit
AdefPot = Adefense*Atodef,
BdefPot = Bdefense*Btodef,

ARoundDmg = (BdmgPot-AdefPot) - how much damage A sustained every round
BRoundDmg = (AdmgPot-BdefPot) - how much damage B sustained every round

in case BRoundDmg == 0 BRoundDmg = some very small number 10^-10? to prevent division by zero

numRounds = Minimum(25, BHP/BRoundDmg , AHP/ARoundDmg)))

BattleADmg = numRounds*ARoundDmg - how much damage A got by the end of the battle
BattleBDmg = numRounds*BRoundDmg - how much damage B got by the end of the battle

in case we have two stacks of units AStack, BStack:
no special or range abilities no spell points, 1 figure and no one tries to run away on the battle map,
side A will pick from team B the unit to attack with the greatest (BdmgPot/BdefPot)/BHP lets call this unit C
and will attack it with his unit with the greatest
AdamagePrecentDiff =
(AdmgPot-CdefPot)/CHP - (CdmgPot-AdefPot)/AHP

when (AdmgPot-CdefPot)/CHP is how much damage A did to C
and (CdmgPot-AdefPot)/AHP is how much damage A received

when AdamagePrecentDiff is negative or the total units AdamagePrecentDiff is negative =
we kill less percentage of the enemy than he kills us
we might consider running away or avoiding combat on the battlefield.

This can be expanded to include figures, spells speed, resistance etc..
Reply

Sorry but I wish it was that simple.

Currently it's like this :

Dmg=1.2*ArmyAttackPot/(60+ArmyDefensePot)

AttackPot and DefensePot are similar to your suggestion but not exactly. But the core idea is they are attack*hitchance and defense*defendchance indeed.

But the problem in the other thread doesn't come from here.

It comes from the question, how do we convert several individual unit's AttackPot and DefensePot (and other stats) into a single army stat. We can't simply add them together.
Reply

Not sure if this is doable, but: Suppose you have five units with effective AttackPots of 9, 5, 3, 3, and 1. Instead of treating them (in effect) as five units attacking with AttackPot [some weighted average of 9, 5, 3, 3, and 1] could you treat them as a smaller number of units attacking with AttackPot of 9? Figuring that defense would make weaker units less effective in general, I might suggest summing the squares of all the units' AttackPots and dividing by the square of the strongest unit's AttackPot to get the total number of virtual units - about 1.5 in my example, or if weird threshold effects are preferable to "half units" attacking (either is probably acceptable for AI-AI battles as long as the overall outcome is reasonably in line with expectations...) you could round to 1.

My guess is that this doesn't work (or at least is suboptimal) because e.g. a stack with a Sprite and four War Bears would have to range-attack like 1 sprite and melee like (say) 4.1 War Bears, and then you either have to recalculate all the stack's numbers every time a unit dies instead of just decrementing one number, or have to ignore mid-battle deaths and then just have a separate calculation for which units died after a battle ends - but I thought I'd at least post the idea in case it suggests a better one to someone (or in case this turns out to be better than I thought)!
Reply

1. what I am actually suggesting is a middle ground between the whole battle simulation and just comparing two large numbers for the two stacks, a kind of mini battle simulation taking top units from each stack and matching them against each other a number of rounds.

2. I don't understand why just adding up multiplication of stats isn't good. multiplying the skills of a very strong monster in one stack will generate a very large number that can't be surpassed by the addition of such multiplication of smaller units from the other stack.

3. can you export two functions of the game to a dll to be modded so we can test it?

first function: produce battle results estimation given two stacks all enchantments and units
second function: simulate a combat given first function input.

using these two functions I can write a test that matches that correlation between many random inputs (random two unit stacks, their enchantments and global/local effects) battle actual result and the estimation function.

this test can test a number of functions and approaches to simulate the battle quickly and pick the one that has the best correlation to the real battle result.
Reply

Quote:Not sure if this is doable, but: Suppose you have five units with effective AttackPots of 9, 5, 3, 3, and 1. Instead of treating them (in effect) as five units attacking with AttackPot [some weighted average of 9, 5, 3, 3, and 1] could you treat them as a smaller number of units attacking with AttackPot of 9? Figuring that defense would make weaker units less effective in general, I might suggest summing the squares of all the units' AttackPots and dividing by the square of the strongest unit's AttackPot to get the total number of virtual units - about 1.5 in my example, or if weird threshold effects are preferable to "half units" attacking (either is probably acceptable for AI-AI battles as long as the overall outcome is reasonably in line with expectations...) you could round to 1.


So looking at two examples...

9,5,3,3,1 - We get ~13.88 here.
3,3,3,3,3 - We should get 15 on this one.

The first army is obviously better than the second but has a lower rating.
Without trying to figure out the math behind it, this seems to do the opposite of intended, instead of "good" units pulling up the value of weaker units slightly, it's weak units dragging down the value of stronger ones.
Reply

(March 20th, 2023, 09:45)GMBarak Wrote: 1. what I am actually suggesting is a middle ground between the whole battle simulation and just comparing two large numbers for the two stacks, a kind of mini battle simulation taking top units from each stack and matching them against each other a number of rounds.

2. I don't understand why just adding up multiplication of stats isn't good. multiplying the skills of a very strong monster in one stack will generate a very large number that can't be surpassed by the addition of such multiplication of smaller units from the other stack.

3. can you export two functions of the game to a dll to be modded so we can test it?

first function: produce battle results estimation given two stacks all enchantments and units
second function: simulate a combat given first function input.

using these two functions I can write a test that matches that correlation between many random inputs (random two unit stacks, their enchantments and global/local effects) battle actual result and the estimation function.

this test can test a number of functions and approaches to simulate the battle quickly and pick the one that has the best correlation to the real battle result.

1. That's not how the system works. This would require implementing a completely new way to handle autobattle.
In the current system each ARMY takes one turn to damage the other and each turn, spells apply their effect to armies similarly. There are no individual units.

2. Because of the above.
Each ARMY has a separate attack, defense, resistance, speed, hp, etc stat. Somewhere around 20 different stats in fact, like special cases such as "flying hp" or "illusion immune damage".
If I make one number from a unit, how could I simulate a battle? It's not just comparing two numbers and the bigger wins, far from it. Each turn damage is dealt based on attack, reduced by defense, considering which type cannot hit which type of hp like melee vs flying, additional damage is dealt based on "save or die" abilities like Death touch and enemy army Resistance, etc.

3. These functions don't exist, if you mean normal, manual combat - if they did we could use that as automatic combat results - and are 100% identical for the automatic combat we're discussing currently.
Reply

lets take a case study to compare 9 to 3

to get 3 you will need something like 1.73 attack potential, 1.73 defense potential 1 health
something like 1 figures swordsmen 4 attack 4 defense 43% to attack 43% to defend 1 health

to get 9 you will need something like 2.12 attack potential, 2.12 defense potential 2 health
something like 1 figures swordsmen 4 attack 4 defense 53% to attack 53% to defend 2 health

before each 3 score swordsmen dies he will kill about 0.73 health of the 9 score swordsman so:

you will need to spend something like 2.74 3 score swordsmen to kill one 9 score swordsman

so 9 =~ (3,3,3)

so it appears the sum is a good estimation, at least for this case.

another example:

how many war bears do we need to kill a moderate strength hero?
hero: 20 attack 60% to hit, 14 defense 40% to def 15 health
war bears: 7 att, 40% 5 def 30% 3 figure 7 health each

the answer is about ~65 war bears needed to kill this hero.
hero score: 1008
bears score: ~59 (I take 2 figures because in intense fight about 2 figures will do damage on average)

so we get 1008 =~ 65X59 = 3835

so the addition doesn't work here.

but:

1008^1.47 = 65*(59^1.47)

so I suggest using SUM(unit score^1.47)

when unit score = attack * to hit * (1+defense) * to defend * hit points
Reply

(March 20th, 2023, 12:04)Seravy Wrote: 2. Because of the above.
Each ARMY has a separate attack, defense, resistance, speed, hp, etc stat. Somewhere around 20 different stats in fact, like special cases such as "flying hp" or "illusion immune damage".
If I make one number from a unit, how could I simulate a battle? It's not just comparing two numbers and the bigger wins, far from it. Each turn damage is dealt based on attack, reduced by defense, considering which type cannot hit which type of hp like melee vs flying, additional damage is dealt based on "save or die" abilities like Death touch and enemy army Resistance, etc.

well, you know the system much better than me and I trust you will implement the best solution. you have certainly done a wonderful job so far, thank you.
Reply

(March 20th, 2023, 12:48)GMBarak Wrote: another example:

how many war bears do we need to kill a moderate strength hero?
hero: 20 attack 60% to hit, 14 defense 40% to def 15 health
war bears: 7 att, 40% 5 def 30% 3 figure 7 health each

the answer is about ~65 war bears needed to kill this hero.
hero score: 1008
bears score: ~59 (I take 2 figures because in intense fight about 2 figures will do damage on average)

so we get 1008 =~ 65X59 = 3835

so the addition doesn't work here.

but:

1008^1.47 = 65*(59^1.47)

so I suggest using SUM(unit score^1.47)

when unit score = attack * to hit * (1+defense) * to defend * hit points

sorry, my bad, correction, it requires about 28 war beats to kill that hero, so the simple addition formula works pretty close here:

1008 =~ 1624

solution to 1008^x = 28*(58^x) is: x=1.167
so:
1008^1.167 = 28*(58^1.167)

so for this simple case I suggest:

SUM(unit score^1.167)
Reply



Forum Jump: