# Calculating combat or spell performance

Beware! Nerdy stuff here!

Today for something different. Today, nerds will rule the post. Today, you better read the post with an aspirin, because statistics will be hitting you on the head.

For a while I’ve been fiddling around with statistics, trying to model the combat performance of our troops. I grudgingly confess I took up the bad habit after being mislead by my napkin math on the table, failing every single tactic that “math told me would work”. I decided it was time to upgrade the statistics I was applying.

# Motivation

It was 6th edition Warhammer.. and 6th edition Dark Elves. It was only later that I realised this edition of the Dark Elves would go down in history as one of the worst armies ever to have graced the table. In good faith and arrogance, I believed that “meagre disadvantage” was easily overcome by superior strategies. That’s what the Druchii.net “how to’s” told me.

So as I played the 6th edition, I valiantly charged my cruel Dark Elves into Dwarven defences, chaos brutes, High Elf cavalry. I learned to do some quick math, working out “I should get a kill here, on average, a kill there, on average and some static combat resolution”.

As my Druchii charged forward, I laughed maniacally. The trap would work!

But then.. that kill didn’t come. And the return damage was greater than expected. And that unit I put in the flank ended up giving more points than they took. And next thing I know, that one charge that included half my army was fleeing.

Binomial distributions, coefficients and other insulting words

So upon trying to figure out what was going on, I asked two things:

• What are the odds to score, say, 0 kills.. as all too often occurred?
• What are the odds of actually getting that average, that misleads me so?

I stumbled upon the binomial distribution, which is a fancy way of saying: if you look at every attack as a “test” with “p” chance to score a wound, then you can get a pretty graphic displaying your chance to score X wounds on A tests.

Let’s do the math briefly: my 6th edition Warrior against a Dwarven warrior would hit on a 4+, wounded on a 5+ and then had to battle the 4+ armour save. On average, 6 attacks would score “half a kill”. But the binomial distribution gives me this pretty graphic instead.

The performance of 6th edition Spearmen

And suddenly it becomes clear.. they won’t really do a damn thing.

# The problem of multiple wounds and killing blow

Armed with this new tool, and two less underpowered editions later, I began investigating the performance of our troops, what to expect and what not. I got hooked.. and ever since I wanted to be able to work out the odds on any possible outcome in the game.

But I stumbled on a problem. How does take into account “multiple wounds”? One could take the outcome of the previous chart, then for every wound inflicted, work out the possible outcomes of multiple wounds. A cumbersome method.

And it became even more complex with killing blow, against creatures with more than a single wound.

# Back to basics!

As is always the case with maths or logical puzzles.. one needs to retrace their steps to find the solution. And when it is found, it becomes “easy”. I thought, since the easy answer was a “binomial distrubution”, based on repeating binomial tests, then certainly the complex version is the “multinomial distribution”.

But after working out a few examples by hand, it proved overly complex, too complex for our needs. We.. can do simpler! Assuming

• px is the chance to score x wounds with a single attack
• Wx denotes scoring x wounds.

An Executioner fighting a war hound has a 51.85% chance to inflict one wound, and a 12.96% chance to score a killing blow, doing 2 wounds. We can write this as:

Score = p0W0 + p1W1 + p2W2

= 35.19% W0 + 51.85% W1 + 12.96% W2

And to work out the score for 14 Executioners attacking that unit, we simply multiply this by itself 14 times:

(35.19% W0 + 51.85% W1 + 12.96% W2) 14

We get this pretty graphic:

Executioners (8th ed) vs Warhounds

# The code is so simple

Up until now, it may look like we did something difficult. But it is, so simple, that it requires only a few lines of code to work. Let’s use Javascript, because everyone can try this in their browser. We simply translate this:

Score = 35.19% W0 + 51.85% W1 + 12.96% W2

Into an array:

`var score = [0.3519, 0.5185, 0.1296];`

And combining it with itself, is simply writing a multiplication function for two arrays:

```function multiply_arrays(array1, array2) {
var result = [];
//fill it with 0's
for(var i =0; i < array1.length + array2.length - 1; i++){
result[i] = 0;
}
//multiply arrays
array1.forEach(function(chance1, score1) {
array2.forEach(function(chance2, score2) {
result[score1+score2] += chance1*chance2;
});
});
return result;
}```

We don’t want to write “multiply_arrays” 14 times, so we add a function “array_to_power” to help us out:

```function array_to_power(base, power) {
var result = [1];
for(var i=0; i<=power; i++){
result = multiply_arrays(result, base);
}
return result;
}

// prints the chance for 11 kills on 14 attacks
array_to_power(score, 14)[11];
// 15.18%```

And there we go! With two simple functions, we manage to model pretty much any combat outcome available.

# A few extras

The magic doesn’t really end there. We can use the same method to calculate some other things, such as the outcome of three dice:

```// begin with 0, since a dice can't roll "0".
var one_dice = [0, 1/6, 1/6, 1/6, 1/6, 1/6, 1/6];
var three_dice = array_to_power(one_dice, 3);```

And the chance for irresistible force can be done by checking the odds to score a 6. Now we can simplify this a bit: we have 5/6 chance to score no 6 (or nothing), and 1/6 to score a single six.

```var sixes_on_one_dice = [5/6, 1/6];
var sixes_on_three_dice = array_to_power(sixes_on_one_dice, 3);
// [0.48225308641975323, 0.3858024691358025, 0.11574074074074076, 0.015432098765432098, 0.0007716049382716049]
// sums up to 13.19%```

# Future work

With this tool in hand, I do plan on investigating the abilities of our troops, spells and some items in more detail. More posts to follow on this, in the near future!

This entry was posted in Theoryhammer by Daeron. Bookmark the permalink.

31y old IT Analyst, married, father, warhammerer.

## 2 thoughts on “Calculating combat or spell performance”

1. Awesome…

statistics might really come in handy when planning strategies. I have only played for a couple of times, but i might just have to rethink on how i play :p

But for those of us that have no idea how to calculate it themselves: wil you ever build like, a tool or something, where users are able to fill in some numbers (say x of unit Y vs A of unit B), and get some statistical results as howmany kills/deaths there will be, (maybe including those really handy graphs)

Kind regards
Sven

• Yup. I’m working on it, in fact 🙂