Description
-----------

I play a war turn-based game, where attacks only have two variables that are visible before a strike: The attacker's military strength $f\_{a}$ and the defender's military strength $f\_{d}$. Whether an attack is successful or not is determined by a series of **$3$ rolls**.

Each roll the attacker and defender will be given a random (*uniform*) multiplier $r\_{a}$ and $r\_{d}$ respectively, where $$0.4<r<1.0$$For a roll to be successful this must hold: $$f\_{a}r\_{a}>f\_{d}r\_{d}$$
At the end of all $3$ rolls the resulting **Victory Type** will be determined as follows:

| Rolls Won | $3$/$3$ | $2$/$3$ | $1$/$3$ | $0$/$3$ |
| --- | --- | --- | --- | --- |
| Victory Type | Immense Triumph (I) | Moderate Victory (M) | Pyrrhic Victory (P) | Utter Failure (U) |

**Casualties** are also calculated through the rolls, in each roll the attacker's and defender's casualties are given respectively by
$$c\_{a} = 0.01·f\_{d}r\_{d} \,\,\,\,\,\,\,\,\,\,\,\, c\_{d} = 0.018337·f\_{a}r\_{a}$$
Importantly, casualties are only applied after all rolls, therefor all **rolls are independent events**. At the end of the 3 rolls, the number of casualties is rounded to the nearest integer.

What I have worked out
----------------------

My knowledge in statistics isn't great, but through experimentation and some intuition I managed to (*after a while*) find that for a given $f\_{a}$ and $f\_{d}$ where $f\_{a} < f\_{d}$ the probability of a successful roll can be given by:
$$P(f\_{a}r\_{a}>f\_{d}r\_{d})=\int\_{0}^{1}{\frac{1}{0.6}\int\_{0.4}^{max(\frac{f\_{a}}{f\_{d}}x,\,\,0.4)}{\frac{1}{0.6}\,dt}\,dx}$$
Which can be simplified to:
$$P(f\_{a}r\_{a}>f\_{d}r\_{d})=\frac{25}{9}\left ( \frac{2f\_{d}}{25f\_{a}} + \frac{f\_{a}}{2f\_{d}} - \frac{2}{5} \right )$$
And thus, if $p$ is the probabilty of a successful roll, the probabilities for each victory type given $f\_{a} < f\_{d}$ are as follows:
$$I=\begin{pmatrix}3\\3\end{pmatrix}p^{3}(1-p)^{0}$$
$$M=\begin{pmatrix}3\\2\end{pmatrix}p^{2}(1-p)^{1}$$
$$P=\begin{pmatrix}3\\1\end{pmatrix}p^{1}(1-p)^{2}$$
$$U=\begin{pmatrix}3\\0\end{pmatrix}p^{0}(1-p)^{3}$$

What I haven't worked out
-------------------------

So all of this leads me to my question, I have been trying to figure out what the expected number of casualties is for a specified victory type, that is, given $f\_{a}$ and $f\_{d}$ where $f\_{a} < f\_{d}$ what are the $E(C\_{a}\mid I)$, $E(C\_{d}\mid I)$, $E(C\_{a}\mid M)$, $E(C\_{d}\mid M)$ and so on...

So far I understand that if I were to set $r\_{a}=1$ this would be true (or at least I think):
$$E(C\_{a}\mid I) = 3\int\_{0.4}^{\frac{f\_{a}}{f\_{d}}}{\frac{1}{\frac{f\_{a}}{f\_{d}}-0.4}\,\frac{f\_{d}r\_{d}}{100}\,dr\_{d}}$$
However given that the bounds of $r\_{a}$ are dependent on $r\_{d}$ and vise versa, since all the possible rolls that would result in a successful roll must follow these:
$$0.4<r\_{d}<\frac{f\_{a}}{f\_{d}}r\_{a}$$
$$\frac{f\_{d}}{f\_{a}r\_{d}}0.4<r\_{a}<1$$
I have not been able to figure out how to calculates these expected values when both $r\_{a}$ and $r\_{d}$ are free to take all possible values they can.

### Double checking

If anyone knows the solution, I wrote a little Python script that ran through the same scenario $1\times 10^{8}$ times where $f\_{a}=3000$ and $f\_{d}=4500$ and these were the results:

| Victory Type | Immense Triumph (I) | Moderate Victory (M) | Pyrrhic Victory (P) | Utter Failure (U) |
| --- | --- | --- | --- | --- |
| Total Outcomes | $325513$ | $5608873$ | $32249407$ | $61816207$ |
| Total Attackers Casualties | $21321676$ | $429922319$ | $2831691198$ | $6117015520$ |
| Average Attackers Casualties | $65.5018$ | $76.6504$ | $87.8060$ | $98.9549$ |
| Total Defenders Casualties | $46393770$ | $739083939$ | $3902378593$ | $6814545685$ |
| Average Defenders Casualties | $142.5251$ | $131.7705$ | $121.0062$ | $110.2388$ |

So whatever the right formula is, when $f\_{a}=3000$ and $f\_{d}=4500$ the expected casualties should match the averages computed above.