Friday, February 12, 2010

Number of attacks to hit

We will examine the number of attacks it takes on average to hit a target monster.

Assuming a probability p of hitting a monster, the probability of missing is 1-p.

The probability of hitting on the first attack = p.

The probability of missing on the first attack, but hitting on the second attack = p(1-p).

The probability of missing on the first two attacks, but hitting on the third attack = p(1-p)^2 .

In general, the probability of missing on the first k-1 attacks, and hitting on the kth attack is: p(1-p)^(k-1) .

To determine the average number of attacks to finally hit a target monster, we take the expectation value of the number of attacks:

sum{k=1, infinity} k p(1-p)^(k-1)

which gives the answer 1/p. (This is using the infinite series 1/(1-x)^2 = 1 + 2x + 3x^2 + 4x^3 + 5x^4 + ...).

With some more work, the variance can be calculated to be (1-p)/p^2.

This probability distribution is better known as the geometric distribution.

http://en.wikipedia.org/wiki/Geometric_distribution

More generally, the problem can be generalized to the case of the average number of times it takes to hit a monster N times. Without going through all the math, one could guess and formally show that the average number of attacks it takes to hit a monster N times is N/p.

In conclusion. With probability p of hitting a monster, the average number of attacks it takes to hit a monster once is 1/p. More generally, the average number of attacks it takes to hit a monster N times is N/p.