combat result: 95% win

Close to 3:1 all the way, although a bit less with larger stacks of defenders.
Looks like promotion just about counterbalances the effect of injured defenders facing a 2nd or 3rd attack.
 
It starts off with almost 4:1 but by 6 defenders it is down to 2.7:1. I would expect further decline as we add more defenders. The calculated limit for swordmen vs. fortified walled spearmen is 2.6:1.

Thanks Pembroke for providing a standard to test formulas against. :)
 
Originally posted by Pembroke
This run took 55 min...

Of course, the algorithm is using brute force. :)

So for a minimum 95% assurance of winning with Veteran Swordsmen against fortified Spearmen in a walled town [on grassland], you need:

Sword v Spear - Ratio
4 v 1 - 4.0
7 v 2 - 3.5
9 v 3 - 3.0
12 v 4 - 3.0
14 v 5 - 2.8
17 v 6 - 2.8

Now we just need to run this 55 minute process just before we attack every town. ;) Thanks, Pembroke!
 
Originally posted by Zachriel
Now we just need to run this 55 minute process just before we attack every town. ;) Thanks, Pembroke!
And for every 20 tries, you still get to find a %$#@ spearman that screws your 55 minutes and plan... ouch. :lol:
 
Actually the town was on grassland... :)

However, might there be a rule in this? Namely the civ combat calculator gives the chance of a single veteran swordman defeating a single veteran spearman fortified in a walled town on grassland as 37.33%. The inverse of that is 2.68 and using that as the factor of attackers to defenders we have:

2-3 vs. 1 : 75%-90%
5-6 vs. 2 : 85%-94%
8 vs. 3 : 90%
10-11 vs. 4 : 88%-94%
13-14 vs. 5 : 92%-95%
16 vs. 6 : 95%

Now, our choice of 95% was arbitrary, but as quite obviously the probability of a single unit battle is linked to the probabilities of a larger battle then there ought to be a relationship to the number of units for a given confidence level, too, right?

But how do we get that? :)

To test this idea I ran the same simulation again but now with knights and pikemen:

Code:
Pikemen:   1       2       3       4       5       6
Knights:
   1       3212       0       0       0       0       0
   2       7225    1015       0       0       0       0
   3       8802    3798     343       0       0       0
   4       9661    6235    1630     113       0       0
   5       9932    8110    3645     683      36       0
   6       9983    9200    5811    1891     292      10
   7       9995    9650    7558    3671     895      93
   8      10000    9915    8703    5563    2061     394
   9      10000    9966    9387    7135    3537    1074
  10      10000    9991    9723    8369    5257    2137
  11        -      9995    9896    9120    6813    3565
  12        -      9999    9960    9586    7934    5072
  13        -     10000    9987    9800    8766    6596
  14        -     10000    9995    9913    9360    7762
  15        -     10000    9998    9966    9650    8518
  16        -       -     10000    9987    9815    9121
  17        -       -     10000    9997    9919    9524
  18        -       -     10000    9997    9976    9780
  19        -       -       -      9999    9991    9905
  20        -       -       -     10000    9993    9954

The combat calculator gives 30.714% for a single unit battle of which the inverse is 3.26 and using that we get:

3-4 vs. 1 : 88%-96%
6-7 vs. 2 : 92%-97%
9-10 vs. 3 : 94%-97%
13 vs. 4 : 98%
16-17 vs. 5 : 98%-99%
19-20 vs. 6 : 99%

Well, it's not linear. Obviously. But I would still like to have a simple rule of thumb maybe adjusted with some variables...
 
Yes, the inverse is my calculated limit ratio. For a large stack of defenders it is a very good approximation.

The trick is to come up with a formula that fits the results BEFORE they merge to the limit.
 
Just a quick word about the statistical side of it:

The "95% formula" will look like K1*(#defenders)+k2*sqrt(#defenders), for any reasonably large number of defenders - the second term reflects the standard deviation of the number of attackers each defender will take out before he perishes.

The exact sizes of K1 and K2 aren't easy to determine except by experiment.

As an approximation, you might treat treat attack strength and defense strength (3 and ~3.7, for the sword-vs-spear-in-city example) as fixed, but instead of counting numbers of units, count total hit points. That is, treat ten veteran defenders as having 40 hit points - maybe a few more, since they get a few more promotions than attackers do.

For each individual *point* in the battle, the attackers have ~44% chance of inflicting damage, ~56% chance of taking it.

Now just look at a negative-binomial distribution, and ask, how many attacking hitpoints will it take, to take out N defending hitpoints? If you use this approximation you will conclude K1~1.23 and K2~2.03, which, for 5 defenders = 20 points, estimates 34 attack points ~ 9 units are needed. This is too low - quite a lot too low - since units that end their turn damaged are unable to "use up" the rest of their hit points the same turn, but would not be a bad approximation if you allowed the battle to go on for several turns, neither side healing or getting reinforcements.

On the other extreme, you can look at it unit by unit - ignoring the fact two attackers might be able to lay into the same defender. Now you get K1~2.68 and K2~2.05, which for 5 defenders suggests 18 units are needed. This is quite a lot too high - still a little too high, but not as much, if you assume damaged defending units are able to heal between turns some but damaged attacking units can't.

The truth lies somewhere in between, and can probably only be discovered by experiement. I would say offhand that somewhere halfway between these two end-member cases would be about right... so how does 2*#def + 2*sqrt(#def) look to you all?

1 spearman -> 4 attacking swordsmen needed
2 spearmen -> 6.8 swords
3 spearmen -> 9.5 swords
4 spearmen -> 12 swords
5 spearmen -> 14.5 swords
6 spearmen -> 16.9 swords
...
10 spearmen -> 26.3 swords.

The predictions of 4 and 6.8 swords for 1 and 2 spearmen are dangerous, since "2 standard deviations from the mean" won't get you to 95% confidence for very skewed distributions. Still - the goodness of fit to the 1-to-6 spearmen experiment is good.

Anyone want to run a simulation for 10 spearmen and see how close 26 is to being right?

(The math was so much easier to do in Civ1!)
 
Siegmund, I'm sure you can do a great statistical analysis on the existing data tables. But by generating a data table we have already solved the problem for that attack/defense combo!

The ultimate goal is a formula or program that inputs the number of defenders and probability of defender win, and outputs the number of attackers.
 
Siegmund:
Anyone want to run a simulation for 10 spearmen and see how close 26 is to being right?

Here:

Code:
Spearmen:   9      10      11
Swordmen:
  24       9860    9443    8379
  25       9944    9710    9005
  26       9963    9830    9412
  27       9985    9905    9633
  28       9997    9947    9806

But I think the problem isn't with the large numbers of units as it approaches the probabilities of the single unit battle as numbers grow. The usual number of defenders is, I think, 1-3 in the Ancient Age to the 6-10 mechs in the Modern Age, so we need a formula or a rule-of-thumb that works about right with low number of troops. It's not critical if it doesn't match with the large number figures, but that ought to make it easier to come up with.
 
Great job! :goodjob:

Just a note on efficiency... you can eliminate the 4 arrays of size T by incrementing AnR, DnR, AHpR, and DHpR in the main loop.

I think 1000 would be a more statistically valid number of trials to use as default, but it does go a bit slow.
 
Originally posted by DaveMcW
Great job! :goodjob:

Just a note on efficiency... you can eliminate the 4 arrays of size T by incrementing AnR, DnR, AHpR, and DHpR in the main loop.

When I first built the structure, I wasn't sure where it was headed, so I built in the extra flexibility. I was going to eliminate the extra arrays when I had a chance to double-check the logic flow.

Thanks. Just knowing you were looking at the code mades me feel a little more secure. I've been trying to do this project between about a thousand other projects -- in bits and bytes. ;)


I think 1000 would be a more statistically valid number of trials to use as default, but it does go a bit slow.

1000 iterations works ok on mine, though it depends on the other parameters.

I haven't found a good way to handle retreat. An Attacker retreating just ignores the turn, as each Attacker only attacks once. But each Defender can Defend more than once, so if the Defender retreats, it has to be removed from the list of available future Defenders. Another array?

Also what are the chances of retreat?

60% Elite
50% Veteran
40% Regular

?
 
Originally posted by DaveMcW
I think 1000 would be a more statistically valid number of trials to use as default, but it does go a bit slow.

Misread that. "default"
Didn't want to jam up anybody's computer.
;)
 
It's in the editor under combat experience.

34% Conscript
50% Regular
58% Veteran
66% Elite

You can count retreating defenders with a single variable, since they always have 1 hitpoint.
 
Has anyone tested how the retreat is actually applied?

Does the possibility of retreat get checked when the attacker loses the round that reduces its hp from 2 to 1, i.e. only when the attacker loses the round? Or is it checked after all rounds that end with the attacker having 1 hp left, i.e. also when the attacker wins a round?

If it's the former then a test fight of two units:

Unit 1: A=1, retreat ability
Unit 2: D=99

run enough times ought to produce a result where the number of retreats is close to the figures given by DaveMcW. (Don't count, of course, the rare cases where the attacker won...) But if it's the latter then the percentage ought to be greater.

I ask because I wanted to see how much the retreat would decrease the chances of capturing the town. (If it's checked only once the effect is negligible unless you are attacking with minimal number of units.)
 
Originally posted by Pembroke


I ask because I wanted to see how much the retreat would decrease the chances of capturing the town. (If it's checked only once the effect is negligible unless you are attacking with minimal number of units.)

Zachriel's Civulation will have retreat added later today, along with Blitz. From my playing with the Civulation, retreat creates a noticable reduction in the chance of victory, but also increase the number of survivors among the attacking forces.

Retreat occurs when the Attacker has one hitpoint. Before attacking, the die is rolled to determine if the Attacker will retreat or complete the Attack. Retreat does not apply if both the attacking and defending units are fast units, or if both are down to one hitpoint.

(Just learned Javascript over the weekend. This is fun. :D )
 
Originally posted by Zachriel

retreat creates a noticable reduction in the chance of victory
...
Retreat occurs when the Attacker has one hitpoint. Before attacking, the die is rolled to determine if the Attacker will retreat

Yes, doing retreat this way in the large scale sim decreases the chances also noticeably in all levels. But is this the way the game itself works?

Could be. I don't know.
 
Are you really enjoying all these calculations ???

:O

Man, just sum up all city defender points and build an army with the double of attack points ! ; )

Or your game will never enter medieval ages !!

:)
 
Originally posted by Pembroke


Yes, doing retreat this way in the large scale sim decreases the chances also noticeably in all levels. But is this the way the game itself works?

Could be. I don't know.

Retreat is grayed out in the simulator. I'll post it when retreat and blitz are working. Blitz, by the way, has a very powerful effect.
 
Back
Top Bottom