Calculating success chance from algorithm Not super sure this is the right *exchange for this question, but here we go.
Let's say I'm writing a game, and in this game the player may attack another unit. The chance of hitting is an "opposed roll" that looks something like this:
An attack lands if: 
(attack * random() + attack * random())
is greater than or equal to
(defense * random() + defense * random())

Where attack and defense are both numbers > 0 and random() returns a (pseudo) random number between 0 and 1 (not including 1). The reason it looks like it does is to ensure that there is a bias towards the "average value" (or rather, towards double the average value, but it doesn't really matter).
How would one go about calculating the "hit chance" for this algorithm (in order to display it to the user)?
Thanks!
 A: The attack is successful iff
$$Ax_1+Ax_2\ge Dy_1+Dy_2\iff A(x_1+x_2)\ge D(y_1+y_2)\iff x\ge \frac{D}{A}y,$$
where $x_1,x_2,y_1,y_2$ are realizations of the $U[0,1]$ random variables and $x,y$ are the respective sums. Now, using the density for sums of two $U[0,1]$ random variables (see the comment above), consider the case $2\ge D/A\ge 1$:
$$\operatorname{Pr}\left(x\ge \frac{D}{A}y\right)=\int_{D/Ay}^1 \int_0^{\underline{y}} xy \,\mathrm{d}x\,\mathrm{d}y+\int_1^2 \int_0^{\underline{y}} (2-x)y \,\mathrm{d}x\,\mathrm{d}y+\int_{D/Ay}^2 \int_{\underline{y}}^1 (2-x)y \,\mathrm{d}x\,\mathrm{d}y+\int_{D/Ay}^2\int_1^{\overline{y}}(2-y)(2-x) \,\mathrm{d}x\,\mathrm{d}y,$$
where $\underline{y}$ is the $y$ such that the minimum $x$ beating this $y$ equals $1$. That is, $x=1=D/Ay\iff y=A/D\le 1$. Similarly, $\overline{y}$ is the $y$ such that the minimum $x$ beating that $y$ equals $2$. Thus, $x=2=D/Ay\iff y=2A/D\le 2$. The integrals represent all cases where the attack is successful, and we need to distinguish the intervals $[0,1]$ and $[1,2]$, because the sums $x,y$ have different densities in these intervals. We only considered the case $2\ge D/A\ge 1$, because for any other case the integral borders or cases will change slightly.
Solving the integrals explicitly (not yet evaluating), we get 
$$[\tfrac14x^2y^2]+[xy^2-\tfrac14x^2y^2]+[xy^2-\tfrac14x^2y^2]+[4yx-x^2y-y^2x+\tfrac14x^2y^2]$$
Now one just has to plug in the $x$ integral borders for each of the 4 terms, then the $y$ borders, and simplifying will give the result. This is a very tedious calculation, maybe it can be done quickly in some symbolic math tool.
