# Expected Value of a DnD/Baldur's Gate Feat

The Baldur's gate feat Savage Attacker lets you reroll an attack, and choose the better of the two attacks.

I am attempting to calculate the expected benefit of this feat. Assume, for the sake of simplicity, that a melee attack has a 1d10 damage, which means it follows a discrete uniform distribution with integer values from 1 to 10 (equiprobable). $$A_1\text{ follows Discrete }U(1,10)$$

If we have savage attack, we take two rolls, and then the better of the two. How do I calculate the expected value of the benefit: $$E[|A_1-A_2|]$$

Update 1: I found this video by Stand-Up Math which calculates the actual probabilities (and not just the expected value)

• If you only want to calculate $E(|X-Y|)$ for two iid discrete uniformly distributed random variables, then there are many ways to do this. Commented Aug 10, 2023 at 6:51
• I only need E(abs(X-Y)) Commented Aug 10, 2023 at 7:23
• Okay I see. @starlight Commented Aug 10, 2023 at 7:47

Here is a pretty fact (it's quite easy to prove): conditional on the two rolls being different, they split the interval into three parts which have identical distribution. (For example, in the image below, the parts have lengths $$2,1,5$$.)

Since the sum of lengths is $$8$$, the expected length of each part is $$8/3$$. Note also that the $$|A_1-A_2|$$ is the length of the middle part plus 1.

That said, using the law of total expectation, \begin{align} \mathrm E[|A_1-A_2|]{} = {}&\mathrm E[|A_1-A_2|\mid A_1\neq A_2]\cdot \mathrm P(A_1\neq A_2)\\ {}+ {}&\mathrm E[|A_1-A_2|\mid A_1= A_2]\cdot \mathrm P(A_1= A_2) \\ {}={} &\Big(\frac83 + 1\Big)\cdot \frac9{10} + 0\cdot \frac1{10} = \frac{33}{10}, \end{align} confirming @Mr.GandalfSauron's computation.

Note also that the expected benefit is not $$\mathrm E[|A_1-A_2|]$$, but rather $$\mathrm E[\max(A_1,A_2)] - \mathrm E[A_1] = \mathrm E[|A_1-A_2|]/2 = 1.65$$.

• Neat. The benefit is indeed $\max (A_1,A_2) - A_1$. The first equality follows from $2\max (a,b) = a+b+|a-b|$ and $EA_1 = EA_2$. Commented Aug 12, 2023 at 20:36
• Can you explain why the expected benefit expression I gave needs to be divided by two. Commented Aug 15, 2023 at 3:14
• @Starlight, the absolute value of difference is your gain compared to the worst of two attacks. Instead, you should be comparing it to a single attack. See also comment above. Commented Aug 15, 2023 at 6:01
• @Starlight The reason is that the benefit is $\max(A_{1},A_{2})-A_{1}$ (i.e. the maximum of the two rolls minus the first roll) and for any real numbers $x,y$, you have that $\max(x,y)=\frac{x+y}{2}+\frac{|x-y|}{2}$ as Alvin points out. So you need $E(\max(A_{1},A_{2})-A_{1}))=E(\frac{A_{2}-A_{1}}{2})+E(\frac{|A_{1}-A_{2}|}{2})$. Now as $A_{1}$ and $A_2$ have same distribution, the first term is just $0$ by linearity of expectation i.e. $\frac{1}{2}\bigg(E(A_{1})-E(A_{2})\bigg)=0$. Hence, what you want is $E(\frac{|A_{1}-A_{2}|}{2})$. Now apply mine or zhoraster's method to get the answer. Commented Aug 15, 2023 at 8:07
• @Starlight One way to see why you need to divide by $2$: in the case where there is actually a difference between the two rolls, the savage attacker feat increases your attack value only when the second roll is the higher one, and that happens only half the time in that case. The other half of the time, the first roll was higher, and the second roll gives no improvement. Another way: If you don't divide by $2$ then you are computing the expected benefit of being able to take the better of two rolls rather than being forced to take the worse of the two rolls. Commented Sep 17, 2023 at 23:10

One way is to directly use some CAS and compute $$\frac{1}{100}\sum_{x=1}^{10}\sum_{y=1}^{10}|x-y|=3.3$$ which will be your expected value i.e. $$E(|X-Y|)$$ where $$X,Y$$ are iid uniform discrete variates on $$[1,10]$$.

The other way is to evaluate this sum by hand.

$$\sum_{x=1}^{10}\sum_{y=1}^{10}|x-y|=\sum_{y=1}^{10}\sum_{x=1}^{y-1}(y-x)+\sum_{y=1}^{10}\sum_{x=y+1}^{10}(x-y)$$

Now both the summands on the RHS are equal by symmetry.

So we focus only on $$\sum_{y=1}^{10}\sum_{x=1}^{y-1}(y-x)$$

Notice that it does not matter if we include the term for $$x=y$$ as we will be only adding a $$0$$.

So $$\sum_{y=1}^{10}\sum_{x=1}^{y-1}(y-x)=\sum_{y=1}^{10}\sum_{x=1}^{y}(y-x)=\sum_{y=1}^{10}(y^{2}-\frac{y(y+1)}{2})$$

$$=\sum_{y=1}^{10}(\frac{y^{2}}{2}-\frac{y}{2})=\frac{n(n+1)(2n+1)}{12}-\frac{n(n+1)}{4}$$

where $$n=10$$ and we are using the formulas $$\sum_{k=1}^{n}k=\frac{n(n+1)}{2}$$ and $$\sum_{k=1}^{n}k^{2}=\frac{n(n+1)(2n+1)}{6}$$

If you plug in $$10$$ in the above expression, you'll get $$\sum_{y=1}^{10}\sum_{x=1}^{y-1}(y-x)=155$$

Hence, by symmtery, $$\displaystyle \sum_{y=1}^{10}\sum_{x=1}^{y-1}(y-x)+\sum_{y=1}^{10}\sum_{x=y+1}^{10}(x-y)=155\cdot 2=330$$ which agrees with the result derived on a CAS.

So $$\displaystyle E(|X-Y|)=\frac{330}{100}=3.3$$

In particular, you can use the same reasoning I did above to calculate that $$\sum_{x=1}^{n}\sum_{y=1}^{n}|x-y|=\frac{n(n+1)(2n+1)}{6}-\frac{n(n+1)}{2}$$