Jump to content

Approximating probability of range attack hitting a target due to spread


stevenlau
 Share

Recommended Posts

Spread of common infantry - Archer:2.25 Crossbowman:3 Javelineer:4 Slinger:3

Spread means how inaccurate the shooting becomes at 100m from target.  The spread is less when closer than 100m.  For example, it is half at 50m.  Thus, archer and crossbowman are proportionally the same: 2.25 x 60 / 100 = 3 x 45 / 100 = 1.35

A projectile (arrow / stone / javelin) is considered to hit a infantry when it arrives at radius < 1.5m from target (indeed, a circle).  A projectile is considered to hit a calvary when it arrives at the 3m x 6m rectangle of the target (indeed, a rectangle), which is a little larger than the size of two infantry.  Dog is smaller, elephant is larger, charriot is larger.

Now, at the beginning of a shoot, after waiting a short initial prepare time (once only), the future location of the target (because it may be walking) is very often precisely predicted, and the projectile is shot there, at a speed around 70m-100m per second, depending on unit.  It should mathematically hit the target at the exact position when the projectile lands.  Therefore, if the target changed direction during this time, the projectile might miss.

Even if the target did not change direction, the projectile might also miss due to the spread.  The exact spread is given by a pair of independent normal random variable at variance of 1m.  It is then multiplied by the spread.  The result is some sort of 2D normal distribution, but since x and y are independent random variables, the 2D CDF is not circular, but more like a square.  It seems super difficult to mathematically calculate the exact probability of it hitting a target.  Let's get a rough idea by assuming the 1D case.  I don't know how much would it deviate from 2D case, would be great if some mathematician could help. (Edit: I solved the 2D case, see reply below)

In the simplified 1D case, I just use some online normal CDF calculator, fixing lower bound at -1.5, upper bound at 1.5, mean at 0, standard deviation at 2.25 x 60 / 100 = 1.35.  Archer hits an infantry at 60m with probability 73.35%.  After an upgrade of spread (-20%), standard deviation = 2.25 x 0.8 x 60 / 100 = 1.08, the probability is 83.51%. 

Crossbowman and slinger hits infantry at 45m with probability 73.35%.  At rank 2 spread -20%, the probability is 83.51%.  Indeed, exactly same as archer at 60m, coincidentally.

Javelineer hits infantry at 30m with probability 78.87%.  At rank 2, the probability is 88.18%.

The best unit would be rank 3 archer plus spread upgrade, at standard deviation = 2.25 x 0.8^3 x 60 / 100, hitting target at 60m with 97%.

Last but not least, when a projectile misses a target, it is not wasted.  It will hit some innocent person standing there.

Reference:

https://gitea.wildfiregames.com/0ad/0ad/src/branch/main/binaries/data/mods/public/simulation/components/Attack.js#L714

Edited by stevenlau
  • Like 2
Link to comment
Share on other sites

  • stevenlau changed the title to Approximating probability of range attack hitting a target due to spread
40 minutes ago, stevenlau said:

Spread of common infantry - Archer:2.25 Crossbowman:3 Javelineer:4 Slinger:3

Spread means how inaccurate the shooting becomes at 100m from target.  The spread is less when closer than 100m.  For example, it is half at 50m.  Thus, archer and crossbowman are proportionally the same: 2.25 x 60 / 100 = 3 x 45 / 100 = 1.35

A projectile (arrow / stone / javelin) is considered to hit a infantry when it arrives at radius < 1.5m from target (indeed, a circle).  A projectile is considered to hit a calvary when it arrives at the 3m x 6m rectangle of the target (indeed, a rectangle), which is a little larger than the size of two infantry.  Dog is smaller, elephant is larger, charriot is larger.

Now, at the beginning of a shoot, after waiting a short initial prepare time (once only), the future location of the target (because it may be walking) is very often precisely predicted, and the projectile is shot there, at a speed around 70m-100m per second, depending on unit.  It should mathematically hit the target at the exact position when the projectile lands.  Therefore, if the target changed direction during this time, the projectile might miss.

Even if the target did not change direction, the projectile might also miss due to the spread.  The exact spread is given by a pair of independent normal random variable at variance of 1m.  It is then multiplied by the spread.  The result is some sort of 2D normal distribution, but since x and y are independent random variables, the 2D CDF is not circular, but more like a square.  It seems super difficult to mathematically calculate the exact probability of it hitting a target.  Let's get a rough idea by assuming the 1D case.  I don't know how much would it deviate from 2D case, would be great if some mathematician could help.

In the simplified 1D case, I just use some online normal CDF calculator, fixing lower bound at -1.5, upper bound at 1.5, mean at 0, standard deviation at 2.25 x 60 / 100 = 1.35.  Archer hits an infantry at 60m with probability 73.35%.  After an upgrade of spread (-20%), standard deviation = 2.25 x 0.8 x 60 / 100 = 1.08, the probability is 83.51%. 

Crossbowman and slinger hits infantry at 45m with probability 73.35%.  At rank 2 spread -20%, the probability is 83.51%.  Indeed, exactly same as archer at 60m, coincidentally.

Javelineer hits infantry at 30m with probability 78.87%.  At rank 2, the probability is 88.18%.

The best unit would be rank 3 archer plus spread upgrade, at standard deviation = 2.25 x 0.8^3 x 60 / 100, hitting target at 60m with 97%.

Last but not least, when a projectile misses a target, it is not wasted.  It will hit some innocent person standing there.

Reference:

https://gitea.wildfiregames.com/0ad/0ad/src/branch/main/binaries/data/mods/public/simulation/components/Attack.js#L714

OP!

Link to comment
Share on other sites

10 minutes ago, stevenlau said:

Spread of common infantry - Archer:2.25 Crossbowman:3 Javelineer:4 Slinger:3

Spread means how inaccurate the shooting becomes at 100m from target.  The spread is less when closer than 100m.  For example, it is half at 50m.

In 1D, but in 2D, with 2 spreads, at twice the distance inaccuracy should increase by 4 times (given how areas change with distance).

 

46 minutes ago, stevenlau said:

The exact spread is given by a pair of independent normal random variable at variance of 1m.  It is then multiplied by the spread.  The result is some sort of 2D normal distribution, but since x and y are independent random variables, the 2D CDF is not circular, but more like a square.  It seems super difficult to mathematically calculate the exact probability of it hitting a target.

What is super difficult is trying to understand what is that you are trying to say. A pair of independent spreads, then you multiply them by the spread? Do you have 3 spreads then? Not even counting target movement? What are x and y, exactly? Please, define things. In any case, assuming x and y are positions, of something in reference to a center, they shouldn't be independent, you should have the condition x2+y2=R2, with R being the displacement from that center, and this changes your integration limits and makes the CDF circular.

If I understand correctly, that something is the arrow, so that circular CDF gives you landing point probabilities (this is a simplification, because the linear horizontal velocity, both longitudinal and transversal, and the quadratic vertical velocity of the parabolic movement will result in an elongated shape on the floor, which is also a simplification when not accounting for air drag, wind, etc). I guess then with some random generator you decide where the arrow fell, and evaluate proximity to nearby units.

Link to comment
Share on other sites

Thanks for trying to understand my imprecise description.  Random normal distribution is a bell shape of standard deviation of 1.  If we multiply it by a spread of 2, it becomes a fatter bell shape, with standard deviation of 2.

Spread is calculated like 2.25 x 60 / 100.  It doesn't change like the way you relate with area.  Consider it like a radius of a circle, centered on the landing point of projectile   At 100m the circle is large, so shooting is inaccurate, at 50m the cirlce is smaller, more accurate.  You are right that the area changes by 4 times, but spread is more like a radius, not area.  This is a 1D value, not 2D.  The random distribution is 2D.  Multiply the 2D distribution with the 1D spread factor to make the distribution fatter, larger, more spread out.

x y are not position of the landing point of projectile, but the random values to be added to the position of the landing point to make it spread out randomly.  With spread, the landing position is no longer a point, but a 2D normal distribution centered on that landing point.

You are right to point out that they "shouldn't" be independent.  But as fact, the source code calculated them independently, probably to speed up computation.  So the condition x^2 + y^2 = R^2 did not hold.  x is just a random value with normal distribution, and y is just another random value with normal distribution.  Together, x and y has no relationship.  That's why the CDF is not circular.  It is weird, but it is the current fact.

Also seems you tried to understand "independent" as separate, and counted 3 spreads.  When I mentioned independent, it is in the sense of random variables.  Since it is 2D, there are only two independent random variables.  Spread is a constant factor, like 2.25 for archer.  At distance of 60m it is adjusted to 2.25 x 60 / 100.  Multiplying the spread would make the random normal distribution larger, fatter, more spread out.

And I guess your final intuitive interpretation is correct.

Edited by stevenlau
Link to comment
Share on other sites

Further thinking about my 1D simplication case, I find that we can obtain the actual probability quite easily.  Since x and y are independent, we can just take the square of the probability, which means probability of x being within +-1.5m of target times the probability of y being within +-1.5m of target.  Next, since infantry is considered as a circle, we further multiply it with the area of circle divided by area of square.

So, the exact probability of archer hitting target at 60m is 73.35% x 73.35% x pi x 1.5 x 1.5 / (3 x 3) = 42.26%.  A spread upgrade would make it 54.77%.  Pretty low!  Would anyone perform experiment to prove it correct or prove it wrong?

Edited by stevenlau
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...