I am trying to write a Java program that calculates the outcomes of a stack of units attacking a stack of defenders using a Monte Carlo type simulation (run combat multiple times and view the potential outcomes). I hope to get it to the point where you can see how different attack orders, upgrades, etc will change your overall outcomes. I think the game does it horribly when you just ram your big stack into a bunch of defenders and I have no idea if I am doing it any better choosing manually.
In order to figure out how to do this I was reading This Article on Combat mechanics and it says this
Based on this it appears that the same amount of damage is done per round regardless of any randomness. This seems incorrect to me for some reason. Is there a step I am missing? My results approximate the "correct" values but I can't help but think that I am missing a step that randomizes the amount of damage each round. Does anyone have any insight into this? Any help would be appreciated.
In order to figure out how to do this I was reading This Article on Combat mechanics and it says this
Round odds
The odds that the attacker will win each round is given by A/(A+D), so the odds the defender wins a round is D/(A+D).
I’m now going to introduce a new variable – the ratio between the attacker’s and defender’s modified strength. This value is R. It is A/D and it controls all of combat. The greater R is, the better the attacker’s odds of winning.
Each round, the attacker wins with odds R/(1+R) and the defender with odds 1/(R+1).
Damage per hit
The attacker and defender both start with their current number of hps (NOT 100 as was previously stated). The attacker’s damage is given by floor(20*(3*A+D)/(3*D+A)). That is, you calculate the value and drop any fractional remainder. The defender’s damage is given by floor(20*(3*D+A)/(3*A+D)).
Going back to R notation, the attacker does floor(20*(3*R+1)/(3+R)) damage and the defender does floor(20*(3+R)/(3*R+1)) damage.
The maximum damage one size can do is 60 per hit. The minimum that can be done is 6. Only those values are possible, regardless of the relative strengths of the units.
Once one side goes below 0 hps remaining, it is destroyed (or retreats). The winner has strength remaining equal to starting_strength*hps/100, but it has fewer hps, so it is more likely to die in further combat. Modified strength no longer matters.
Based on this it appears that the same amount of damage is done per round regardless of any randomness. This seems incorrect to me for some reason. Is there a step I am missing? My results approximate the "correct" values but I can't help but think that I am missing a step that randomizes the amount of damage each round. Does anyone have any insight into this? Any help would be appreciated.