2
\$\begingroup\$

I'm trying to calculate the expected ttk for weapons in my game but I'm having trouble because players can miss and enemies can heal.

Let's say an enemy has 100 health and every second you have a \$p\$ probability of dealing \$d\$ damage. The enemy heals for a consistent \$h\$ health per second.

I've broken it down to this piecewise recursive equation: $$ T(x) = \begin{cases} 0 & x\leq h \\ 1+p*T(x+h-d)+(1-p)*T(x+h) & h\lt x\leq 100 \\ T(100) & 100\lt x \end{cases} $$ where \$T(x)\$ represents the average ttk of the player in seconds given they are on \$x\$ health, but haven't made any progress on finding a closed form version.

\$\endgroup\$
1
  • \$\begingroup\$ Do you need a continuous equation, or do you only need a usable result? If the former, this is a math problem ; if the latter, you can run Monte Carlo simulations and it becomes a problem of presenting the data in a usable format. \$\endgroup\$
    – Sacha
    Nov 20 at 23:10

2 Answers 2

3
\$\begingroup\$

If an approximation is sufficient then on average the target will take p*d damage per second and heal for h, so their net life loss will be p*d-h per second. Assuming p*d-h > 0, the time to kill is approximately:

$$\frac{x}{p*d-h}$$

The reason this is an approximation is that it does not take into account overkill damage. For example, against a 100 health target (with zero healing) weapons that deal 60 or 90 damage both take 2 shots to kill, but this formula will return a different value.

If you need an exact value, then there will be no nice closed form for this. The easiest approach is to simulate a lot of iterations, or you could build the health transitions into the state space of a Markov chain and compute the absorption (death) percentages at each second. I have a post on the statistics exchange with some python code for Markov chains, but it's probably not necessary for your use case.

\$\endgroup\$
2
  • \$\begingroup\$ I appreciate your response, but burst damage is important for my use case. Are you sure there's no closed form for this, or is one just not known? \$\endgroup\$ Nov 20 at 23:58
  • \$\begingroup\$ the formular returning a different value should be no problem since the healing during missed shots make up for the difference. A weapon with 90 damage per hit is much more likely to kill the 100hp target in 2 shots than the weapon with 60 damage. With h = 10 one missed shot would take the amount of hits required up to 3, while the 90 damage weapon would need 6-7 misses to take the hits required up to 3. This should hold true except for edge cases where p = 1 or close to 1. \$\endgroup\$
    – datacube
    Nov 21 at 14:42
1
\$\begingroup\$

Partial answer: no healing

In your case the healing is the culprit, which makes the whole thing extremly hard to calculate. I hope my equation for the special case of h = 0 (no healing) helps you along the way.

Minimum amount of shots required \$n_{min}\$ (all shots hit) $$ n_{min}= \lceil\frac{x}{d}\rceil $$

Chance for a killing sequence of only hits (\$n_{min}\$ shots and all hit): $$ P(n_{min}) = p^{n_{min}} $$

Chance for a killing sequence with \$k\$ misses (\$n_{min} + k\$ shots) $$ p^{n_{min}}*(1-p)^{k} $$ Since the missed shots can happen anywhere in the sequence, we have to multiply this by the number of possible permutations. Since this is a form of Binomial distribution this would be: $$ {n_{min}+k \choose n_{min}} $$ But this contains also permutations that end in one or multiple missed shots, where the target would be already dead before the end of the sequence. So lets only account for those permutations that end in a hit. With one event fixed we have to substract 1 from top and bottom. $$ {n_{min}+k-1 \choose n_{min}-1} $$ This leads us to the formular to calculate the chance to need any amount of shots to kill the target.

$$ P(n_{min}+k) = {n_{min}+k-1 \choose n_{min}-1} *p^{n_{min}}*(1-p)^{k} $$

To get the average number of shots required, we multiply each chance with the amount of shots and sum everything up. Since it is possible to miss indefinetly, it is an infinite sum with ever shrinking summands.

The average number of shots neccessary (\$n_{avg}\$)is : $$ n_{avg} = \sum_{k=0}^\infty( (n_{min}+k)*P(n_{min}+k)) $$ $$ n_{avg} = \sum_{k=0}^\infty( (n_{min}+k)*{n_{min}+k-1 \choose n_{min}-1} *p^{n_{min}}*(1-p)^{k} ) $$ Maybe someone else is able to fit the healing into this.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .