I was designing some ships last night at around 4 AM (damn you Stardock!) and was trying to work out in my head how they would stack up against some of the ships my opponents were fielding. Unfortunately, figuring out damage probabilities for differing amounts of attack and defense were too much for me to do in my sleep deprived state, so I found myself making a lot of rough estimates. This morning the question kept nagging at me, so I decided to grab a pencil and paper and find a formula for the average damage that can be expected for any pair of attack and defense values. After a good amount of head scratching, I found not one but two formulas, for slightly different situations:
If the attack value of one ship ship is less than the defense value of the other then use this formula (where "a" is attack value and "d" is defense value):
(a + 1) (a + 2)
Avg. damage = ---------------
6 (d + 1)
If the attack value is greater than the defense value, then use this longer verson:
a (a + 1) (a + 2) - (a - d - 1) (a - d) (a - d + 1)
Avg. damage = ---------------------------------------------------
6 a (d + 1)
The simpler formula can actually be used whenever a <= d + 1, not just when a < d. It works out that the formulas both give the same answer when a is equal to d or (d + 1).
There may be a way to simplify the second formula, but I was not able to find one. When I multiplied the numerator out, I got:
d^3 + 3 a^2 + 3 a^2 d - 3 a d^2 + 3 a - d
Avg. damage = -----------------------------------------
6 a (d + 1)
That is pretty ugly, and harder to remember than the version above. If anyone sees any factorization that can be done to simplify things, I'd love to hear it.
I'll type up my derivations of the two formulas in a bit and post them later. The only thing that might be a bit controversial about them is that I have assumed that the attack roll is always at least one, whereas the defense roll may be zero. This does not agree with what the developers have told us, but it more closely matches what I have seen in my games. (I have tried to do some tests in the game, but kept getting really odd results, like a 1 attack/1 defense fighter doing 5 damange in a single shot.) The change to the formulas is not very big if you want to calculate using a 0 based attack though: muliply the equations above by "a / (a + 1)".
Edit:
The Derivations
First, we need to understand what it is we are taking the average of. The damage delt by a single shot can be thought of as a point in a probability space, where one axis represents the attack roll and one axis representing the defense roll, like so:
|| Attack Roll
|| 1 | 2 | 3 | 4 | 5 |...
===========++===+===+===+===+===+~~~
0 || 1 | 2 | 3 | 4 | 5 |...
---++---+---+---+---+---+~~~
1 || 0 | 1 | 2 | 3 | 4 |...
---++---+---+---+---+---+~~~
2 || 0 | 0 | 1 | 2 | 3 |...
---++---+---+---+---+---+~~~
Defense 3 || 0 | 0 | 0 | 1 | 2 |...
Roll ---++---+---+---+---+---+~~~
4 || 0 | 0 | 0 | 0 | 1 |...
---++---+---+---+---+---+~~~
5 || 0 | 0 | 0 | 0 | 0 |...
---++---+---+---+---+---+~~~
...~~...~...~...~...~...~...
The size of the space depends on the probability space depends on the attack and defense values of the ships we are considering. The space I drew above would work for a ship with 5 weapon strength firing on a ship with 5 defense. The important thing about the probability space is that each of the points in the space is equally likely to be the result. So, to find the average value, we simply need to add up all the values and devide by the area of the space.
While it is possible to add up by hand the values in a small space like the one above, you would not want to try it for a space that was has dimensions that are much bigger.
Fortunately, there is a pretty obvious pattern to the values in the space. They form a triangle in the upper right corner of the space. We can use that pattern to find a formula for the sum.
First lets make a formula for the total value of each column as we go from left to right. The first column has just 1 (and a lot of zeros). The second column has a 2 and a 1 (and zeros). The nth column has the first n natural numbers (and zeros). Since we are adding everything up, we can ignore the zeros and just add up the numbers. There is an easy formula for the sum of the first n natural numbers:
n (n + 1)
Sum(for i=1 to n, i) = ---------
2
Now we make a sum of the column totals (a of them, since columns represent the ship's attack values). We'll try to break it up in to pieces, then deal with each individually:
[ n (n + 1) ] [ n^2 + n ]
Sum[for n=1 to a, --------- ] = Sum[for n=1 to a, ------- ]
[ 2 ] [ 2 ]
Sum(for n=1 to a, n^2) + Sum(for n=1 to a, n)
= ---------------------------------------------
2
We already know how do to the second of those sums, but for the first we need the formula for the sum of the first n squares:
n (n + 1) (2 n + 1)
Sum(for i=1 to n, i^2) = -------------------
6
Plugging that in (along with the previous one) gives:
[a (a + 1) (2 a + 1) a (a + 1)]
[------------------- + ---------]
= [ 6 2 ]
---------------------------------
2
[2 a^3 + 3 a^2 + a a^2 + a]
[----------------- + -------]
= [ 6 2 ]
-----------------------------
2
[2 a^3 + 6 a^2 + 4 a]
[-------------------]
= [ 6 ]
---------------------
2
a^3 + 3 a^2 + 2 a
= -----------------
6
a (a + 1) (a + 2)
= -----------------
6
So we have have a formula for the sum of the columns. At least, we have for any tall and skinny probability space, where there are lots of zeros at the bottom of each column. What if the space is short and wide? Then some of the columns won't have all the values we counted. This will happen any time the attack value is greater than the defense value by more than 1. Here's an example, 5 attack vs 2 defense:
|| 1 | 2 | 3 | 4 | 5 |
===++===+===+===+===+===+
0 || 1 | 2 | 3 | 4 | 5 |
---++---+---+---+---+---+
1 || 0 | 1 | 2 | 3 | 4 |
---++---+---+---+---+---+
2 || 0 | 0 | 1 | 2 | 3 |
---++---+---+---+---+---+
So we need to correct for the space we counted, but which is not actually present in the real probability space. Fortunately, the missing piece has the same pattern as the whole space does! Ignoring the columns that are all zeros, it starts with a column with a 1, then has a column with 1 and 2, etc. So we can use the same formula we calculated above for the correction factor. How many columns are in the space we are correcting for? By looking at the space, you can see it is a - d - 1 (where a is the attack value and d is the defense value). In the example above, that is 2 columns. So, the sum for short and wide spaces is:
a (a + 1) (a + 2) - (a - d - 1) (a - d) (a - d + 1)
---------------------------------------------------
6
Now we have two formulae for the sum, and we can construct our average. This is where I stray in to controversial (and possibly simply wrong) territory, as I belive that attack rolls are always at least 1, despite what the developers have said to the contrary. In any case, what we need is the area of the probability space. In my view, that is a (d + 1). If you belive that attack rolls may be zero, add a column of zeros to the beginning each of the spaces I have drawn. The area will then be (a + 1) (d + 1). The average is the sum of the values, devided by the area:
[a (a + 1) (a + 2)] | [a (a + 1) (a + 2) - (a - d - 1) (a - d) (a - d + 1)]
Sum [-----------------] | Sum [---------------------------------------------------]
Average = ------ = [ 6 ] | Average = ------ = [ 6 ]
Area ------------------- | Area -----------------------------------------------------
a (d + 1) | a (d + 1)
|
|
(a + 1) (a + 2) | a (a + 1) (a + 2) - (a - d - 1) (a - d) (a - d + 1)
= --------------- | = -----------------------------------------------------
6 (d + 1) | 6 a (d + 1)
So there you have it! Formulae to use to calculate the average damage for each shot. I hope this will be useful to you in designing your ships. Let me know what you think.