Target audience: This post requires some basic understanding of algebraI've tried to minimize the math and maximize the thought stream; any improvements welcome.
(https://s6.postimg.org/uixfn393l/Lady_Luck.png) | Building a new weapon? Or a machine that can fail? Or a test for a loot drop? This is a how-to on dancing with Lady Luck.
It isn't as simple as an average because an average only works over a long haul. But there's a method to the madness that works for any luck-based test for success, and it's accuracy and the length of the previously mentioned long-haul are both factors in the solution.
The Formula Maybe we know a toHit chance and want to know how many times it will take to not miss with the whole burst. numberOfShots = log(burstFailure)/log(chanceToMiss)
|
Chance of FailureTurns out it's much more convenient to think in terms of failure than success for this type of problem. So we might want a series of shots to completely fail only once in a while. Lets call that
burstFailure. The more shots we fire in a burst the less likely it is for all of them to miss, which we're calling
burstFailure.
If we know the chance to hit then we also know the chance to miss (100% -
chanceToHit). So we can be precise about the chance of having a
burstFailure event:
burstFailure = chanceToMiss x chanceToMiss x chanceToMiss... with one
chanceToMiss for each shot, which can be stated more simply as
burstFailure = chanceToMiss^numberOfShots
So now we got a juicy new toy
burstFailure, what can we do with it?
Let's say we want the burst failure outcome to happen only once out of every twenty times we fire a burst; 1/20 = 5% chance of
burstFailure. We know that as we increase the number of shots fired in a burst the chance of them all missing goes down. And we want it to go down to our chosen 1 in 20 chance of them all missing. So how many shots is that?
burstFailure = chanceToMiss^numberOfShots | formula we worked out earlier |
1/20 = chanceToMiss^numberOfShots | substituting our chosen value for burstFailure to happen about 1 time out of every 20 |
log(1/20) = log(chanceToMiss) x numberOfShots | taking the log of both sides of an equation |
log(1/20)/log(chanceToMiss) = numberOfShots | dividing both sides of an equation by log(chanceToMiss) |
So now we have nice and tidy formula that takes as input the
chanceToMiss of a single shot and returns the number of shots needed to reach our desired
burstFailure rate.
Great feedback... I feel like this is something that I wanted to know, but never knew that I wanted to know it. I will say that I was disappointed at the end of your tutorial though... how many shots was it in your example? What a cliff hanger ;)
Maybe include some real numbers or example to illustrate your point?
(https://s6.postimg.org/eq69buqc1/Medusa.png) | An example brought to life
Let's say we have our favorite Space Chicken Launcher with the Homing Chickens mod installed. At our current range of ten chicken-flaps, four out of five of our avian harbringers of death and destruction will likely strike their target. So we have made an 80% chanceToHit, which also means we made a 20% chanceToMiss.
A brief aside on Confidence levels Previously on the animal channel, we decided to say only once in twenty should a burst of fire completely miss all shots. This is technically called a confidence level of how certain we wish to be of hitting. At one end of the spectrum we can be 100% certain and at the other end we have no certainty. Interestingly enough both of these ends have something to offer.
If I roll a pair of six-sided dice and add them together, I can be 100% certain the outcome will be a number between 2 and 12. The merit of this is that it shows us the full range of what is possible. As I lower my confidence, or increase my willingness to be wrong some of the time, I can narrow my answer down to what is probable.
And now, back to the show We have chosen to allow an oops once out of twenty runs, so an error may happen 5% of the time. In this way we can say we are 95% confident in our answer.
These two decisions -- chanceToMiss and burstFailure -- are all that is needed to use our formula
numberOfShots = log(burstFailure)/log(chanceToMiss) | Our secret recipe, from the vault at Salsa & Salsa... |
numberOfShots = log(1/20)/log(1/5) | substituting burstFailure = 1/20 and chanceToMiss = 1/5 |
numberOfShots = 1.8614 shots |
So our amazingly awesome Space Chicken Launcher with the Homing Chickens mod requires only two shots to meet our high standards of excellence.
A way to cross-check this is to say 20% chanceToMiss x 20% chanceToMiss = 4% chance to miss both shots, which is below our 5% threshold.
|
(https://s-media-cache-ak0.pinimg.com/736x/22/f8/75/22f875c20fb7c37791c9057360d4424f.jpg) | What if I want to design the number of shots it takes
Doctor Theopolis emerged from the Lab-O-Doom with a dismembered hand, and proposed attaching a magazine-fed pea shooter to the pirate recuperating in his facility. He had some design parameters in mind:
- It's a rapid fire weapon
- Not particularly accurate
How do we translate this desire into an implementation? As an arbitrary and artistic choice, we decide that maybe a batch of half a dozen shots is fired and they all miss their target once out of every three times.
And we'd like a function that returns the chanceToHit when given our design parameters.
burstFailure = chanceToMiss^numberOfShots | Given |
1/3 = chanceToMiss^numberOfShots | substituting our chosen burstFailure of one in three bursts |
1/3 = chanceToMiss^6 | substituting our chosen batch size of half a dozen shots |
We've got it down to our one desired variable, so it's an equation with a single scalar-value result. Pretty much. Anyway, moving on from the realm of imaginary numbers...
Our desired chanceToMiss, which will lead directly to chanceToHit, is trapped behind the magic field of an exponent.
Can anyone cast the ancient incantation necessary to bring it out?
|
(https://s-media-cache-ak0.pinimg.com/avatars/anglewyrm6_1455250071_280.jpg) | Ok, I'll do it We have an equation that looks like so: 1/3 = chanceToMiss6 and the chanceToMiss has an exponent of 6 This just won't do. So how can we get that power of six to be a power of one? It's pretty simple: Divide the power by six. On both sides, Daniel-san.
( 1/3 )1/6 = chanceToMiss6/6 | raising both sides to the power of 1/6 |
0.8327 = chanceToMiss | just whipping out the ole calculator |
chanceToHit = 1 - 0.8327 = 0.1673 = 17% | chanceToHit = 1 - chanceToMiss |
|
You can choose to either do the math behind the post-processing curve and stat weighings, along with the accuracy^numberoftiles with the different accuracy values for x% of total range....
...Or just be glad someone already did this for you and use this (https://ludeon.com/forums/index.php?topic=30907.0).
(https://s-media-cache-ak0.pinimg.com/564x/67/bd/21/67bd21d0d61cf40740ed596f83eb98f7.jpg) | Need some accompaniment? Do be do be doowaaaaah |
I wont lie, i used tons of tools like the one posted when I was taking civil engineering in school. Its still an asset to know the nuts and bolts of how they get the numbers, good post.
(https://s-media-cache-ak0.pinimg.com/736x/b1/ba/eb/b1baeb06250b802468581213db9bd547.jpg) | Was kinda hoping someone would ask what a fractional exponent means.
But thanks for the complement. |
...but AngleWyrm, what does a fractional exponent mean? ;)
(https://s-media-cache-ak0.pinimg.com/564x/a1/3c/97/a13c97fdacda1a365dc718bb20c30f88.jpg) | Glad you asked! It's called a root.
someVariable3 is just a simpler way of saying someVariable x someVariable x someVariable So 43 = 4 x 4 x 4 = 64.
This operation can be reversed, to travel back in time and space, to do the time warp again.... 641/3 = (something) x (something) x (something) = 4
We're most familiar with square roots and somewhat with cube roots. 32 = 3x3 = 9, and the reverse: 91/2 = (something)x(something) = 3 so we can see that 91/2 is the same thing as the square root of 9
23 = 2x2x2 = 8, and going the other way, 81/3 = (something)x(something)x(something) = 2 so we can see that 81/3 is the same thing as the cube root of 8
|
(https://s-media-cache-ak0.pinimg.com/originals/dd/7d/c9/dd7dc9a94afc72dcfa3b9f8f4c7d09f7.jpg) | Quote from: jimthenoob on April 06, 2017, 03:11:17 PM I wont lie, i used tons of tools like the one posted when I was taking civil engineering in school. Its still an asset to know the nuts and bolts of how they get the numbers, good post.
There are two questions that gamers regularly express interest in
- How many times do I have to do this?
- Seems I've done this a bunch, shouldn't I be there yet?
Both of these questions are variables in a single formula, and because it is a mathematical expression it can be swapped around to solve for either one. |
How many times do I have to do this?
set confidence level to 95%
numberOfTimes = log(1 - confidence) / log(1 - chanceOfSuccess)
Example: Some RNG process has a 16% chance of success
numberOfTimes = log(1 - 0.95) / log(1 - 0.16)
numberOfTimes = 17.2 tries (https://www.google.com/search?q=log%281+-+0.95%29+%2F+%281+-+0.16%29&ie=utf-8&oe=utf-8#q=log(1+-+0.95)+/+log(1+-+0.16)) to achieve 95% confidence in getting at least one success.
How sure am I? Shouldn't I be there yet?
set numberOfTimes to what has already been done
confidence = 1 - (1 - chanceOfSuccess)
numberOfTimesExample: I have already run 3 tries of an RNG process that has a 16% chance of success
confidence = 1 - (1 - 0.16)
3confidence = 41% certain (https://www.google.com/search?q=1+-+%281+-+0.16%29%5Bsup%5D12%5B%2Fsup%5D&ie=utf-8&oe=utf-8#q=1+-+(1+-+0.16)%5E3) that I should already have at least one success.
Game developers are in a position that gamers rarely have occasion to experience; they have a need to look at that same equation from the third possible perspective: They have an idea of the number of times something should happen, and the confidence with which they want that to be true. What they want to calculate is the chance of success given those two variables. This perspective also comes up in scenarios where data is being tested to determine the chance of success.
What is the chance of success?
set numberOfTimes to what is desired
chanceOfSuccess = 1 - (1 - confidence)
1/numberOfTimesExample: I want it to take up to 5 tries before they're 95% certain to have it
chanceOfSuccess = 1 - (1 - 0.95)
1/5chanceOfSuccess = 45% chance (https://www.google.com/search?q=1+-+%281+-+0.95%29%5E%281%2F5%29&ie=utf-8&oe=utf-8) to succeed on any given try.