Estimate how many times to draw a score before going above a given limit

35 Views Asked by At

Case:
You have a hat with 10 notes in it. The notes can have values A, B or C written on them. Each time you draw a note, you add its value to the total score, put the note back and draw again. How many times would you expect to draw to go above or equal to a total score of X?

Example:
There are 6 notes with the value of 100, 3 notes with the value 20 and 1 note with the value 1000. How many times would you expect to draw to get a total score above 500?

Why?:
I am trying to write a game where you can have a normal hit (in this example, 100), a hit where the enemy dodged (in this example, 20) or a critical hit (in this example, 1000). How many rounds would it take you to kill an enemy with HP of 500? This calculation is needed to balance different builds and weapons in the game.

What I tried so far:
I started off by trying to simplify the problem by ignoring the dodge damage and just look at normal hit vs critical hit. Then I drew up different "probability trees" for different scenarios (eg, A=20, B=100, X=25; A=10, B=10000, X=100; A=400, B=800, X=2005; etc and with different probabilities for A and B, lets call them D and E).

I came up with lots of different functions to manually calculate each example, but I have not been able to come up with one common function for this where I can just replace the variables and get the result. Each function is very case specific.

Example, A=400, B=800, D=0.9, E=0.1, X=2005
Photo of the "probability tree" and how I ended up with this function for this specific case $$3*0.1^3+4*(3*0.1^2*0.9^2+3*0.1^2*0.9)+5*(4*0.1*0.9^3+0.1*0.9^4)+6*0.9^5$$

Looking at different cases like this, I came up with this function, but it is just "almost right" for many cases (like the one above) and probably way off for other cases. (The biggest issues are the constants 3, 3 and 4 inside the brackets above..)

G - min number of rounds (all crit damage): $RoundUp(X/B)$
H - max number of rounds (all normal damage): $RoundUp(X/A)$

G=3, H=6

$$NrOfRounds = \sum_{k=1}^{G}(E^k\sum_{n=k}^{H}(n*D^{n-1}))$$

This question was originally posted here

1

There are 1 best solutions below

1
On

Let $N_A$ be the number of notes of value $A$, and similarly for $N_B$ and $N_C$. Let $N = N_A + N_B + N_C$ be the total number of notes. In a single draw, the probabilities of getting each note value are $$p_A = \frac {N_A}N,\quad p_B = \frac {N_B}N,\quad p_C = \frac {N_C}N$$ The expected value obtained from a single draw is therefore $$E = p_AA+p_BB+p_CC$$ Because the draws are independent events, this doesn't change with additional draws. So the expected value after $n$ draws is $nE$.

Thus one would expect it to take $$n = \left\lceil\frac X{E}\right\rceil = \left\lceil\frac {NX}{N_AA + N_BB + N_CC}\right\rceil$$ turns to reach a total of $X$ or more points. (The outside semi-brackets denote rounding up.)