Navigation:Home arrow Calculators arrow SewerRat's Gambling Calculator Saturday, 17 May 2008
Logo pic
Still alive until the next Slashdotting...

 

 
News
Submit News
Community
Strategy
News
Articles
Calculators
Community
Discoveries
Information
One on One
Strategy
Submit News
News
Community
D1 FAQ
Information
Jarulf's Guide
Mods
One on One
Scene
Strategy
Submit News
Home
About Us
Chat
Contact Us
Donate
FAQ
Forum
History
Legal Info
Link to Us
Search
Site News
 
 


 
 
SewerRat's Gambling Calculator PDF Print E-mail
Written by SewerRat   

This calculator no longer applies to the latest version of Diablo II. It remains here for archival use only.

With SewerRat's Gambling Calculator, you can determine just how much a target item is going to cost you in gambling money for a certain chance to get it.  This is a small Visual Basic program which will allow you to input what kind of item you're looking for.  Then, you specify one of three things: how much money you're willing to spend for it, the number of gambles you're willing to try for it, or the percent chance you'd like to have to find the item.  All mathematically developed and coded by .

You can download the VB program right here (39 KB).

 

The Math Behind the Calculator by SewerRat

Ok, I've bothered you off and on with weird statistics questions that I usually knew the answer to. Now I'll go into the full explanation.

In a game I play, they have gambling. How it works is that there are 4 types of item sub classes. Unique, Set, Rare, or Normal Magical. So you click on an item, and the computer does some rolling. There is a 3% chance that the item is unique, 5% that it is a Set item, 7% that it is a rare. Set items are the hard one because there are a total of 2 set rings, and 7 set amulets. So when you gamble on a ring and get a Set ring, it could be the one you want or the other.

I wanted to design a utility that would let you enter the number of gambles you took, and told you what your percentage chance of getting the item you wanted was. Also, I wanted to be able to enter my desired percentage chance, and it would tell me how many gambles I needed.

As both of us worked out 50% is the average for percentage chance that you'll have an item after N gambles.

The Basic Formulas

It's easy enough to show, that if an item has a Ps percent chance of succeeding and is being gambled on n times, we get:

Image
Image

Image

The Harder Stuff

Now we start to look at the harder stuff. Most of the time a successful gamble on one item type (ring for example), will lead to only one possible item. In the case of some of the set items, this is not the case. Now I repeat the fundamental questions from above: 1) If I gamble n times, what is my percentage, P, of getting the item I want? 2) If I want a P percent chance of finding the item how many gambles, n, do I need to do?

Intuition would tell you that to find the overall percent, we find the percent that event 1 occurs, P1, and multiply it by the percent that event 2, P2, occurs: (I'm solving for P, the going after n)

Image
ImageImage

Image

Image

So simple, so elegant, so wrong. I like to refer to this as the "False Messiah". There is a hidden error here. One that I'll get to later when I finally grind my way though all of this. To show that it is wrong, I'm going to use some numbers. While I realize that this isn't formal, it illustrates the point well.

I'm going to use the set rings. There are two of them (s=2), I want to know how many gambles I need to get a 50% chance of success (P = .5) of getting the one I want. It doesn't matter what Pf is for this problem.

Image

Now the ln(0) isn't a good thing to get when you are looking for the number of gambles you need.

Something here is very wrong and it took me while to work out what. The main problem has to do with the basic question. It's very unique in the statistics world. This is not the type of question we ask. We care about things (among others) like:

Image

But not usually the situation where we don't know how many gambles it would be at each step:

Image

Remembering our Definition of N as the number of gambles needed, and P as the percentage chance that we have of getting the item we want. Note that it is NOT the same as the percentage that we would get like in first figure. This is because of how we defined P, not some special understanding of the universe.

The Breakthrough?

Now that hopefully I've explained why that the "False Messiah" is false, now I've got to come up with an answer to the two fundamental questions. I found it almost impossible to attack P directly. We just don't know what P1% and P2% are. Though it would be possible to assume that P1 = P2 = P, but I'm not going to bother with that.

The key is how N relates to N1 and N2. To do this, I'm going for another example. If P2 = 50% and we have s=2 (two items), then N2 = 1. That means that if we see 1 successful output from the first box, the we'll get our desired 50%. Now if we want P2 = 51%, then this gives an N2 = 2. That means that we need 2 successful gambles for this to occur. Now if it takes 14 gambles for the first box to kick out one successful, N1 = 14, then we would total 28 gambles, to get our 2 successful. This reasoning leads easily to:

Image

Going back to the expression for n out of the "Basics" section, and now upgrade it with our new notation. We're using subscripts 1 and 2 to distinguish the pair.

ImageImage

Image

Well, This doesn't seem to have got us very far. We're still left with a judgment on P1 and P2 and that is not what we want. Now time to bring it on home. I'm going to make the assumption that there is an equation that relates total number of gambles, N, to the desired percentage P. I'll keep it in the same form as in the basic equation section.

Image

Image

So, now it's time to try and make sense of this all. Pf is the over all percentage that it will fail. It has a Pf1 chance to fail the first test (and not see the second test at all). That means that it has a Ps1 chance of making it to the second test. Now it has a Pf2 of failing this new test. This leads to:

Image

It is fairly easy to convert this into Pf1 and Pf2 But this is not necessary. It is enough that the quantity Pf can be found from things we already know. Now we solve for P:

Image

Now to that age old question of what the heck to use for P1 and P2? I mentioned before that intuition will lead to P1=P2=P. Let's see how this checks out using an example. Back to those Set rings. Pf1 = 0.95, Pf2 = 0.5, P1 = 0.5, P2 = 0.5.

Image

That sure doesn't look like P = 0.5 to me. So We can't assume that P1=P2=P. So what to do about it? I'm going to put the equation for P back into terms for N1 and N2.

Image

The Bottom Line (and a little luck)

Luckily for us, in this problem we don't really need to know how many gambles would occur at each of the different percentages, N1 and N2, because N (the total gambles) will bring it on home for us. To see this look at the two questions.

1) If I gamble n times, what is my percentage, P, of getting the item I want?

This gives us N, problem solved! We've got P, we've got N, we've got everything.

2) If I want a P percent chance of finding the item how many gambles do I need to do?

N may not be specified but P has. So it is trivial to solve for N.

So the bottom line is real easy (P is the desired percent, N is the number of gambles, s is the number of items that have the same base item type.

ImageImage

Image

These allow us to treat all of the cases the same and is easy to code.

The Final Frontier (Unique Rings)

Now we move to the last statistical problem in this program, the unique rings. As you know there are three of them. To get the second, you must have the first. To get the third, you must have the previous two. User input requests the which of the three rings that they are intersted in finding. Because of this, I assume they stop gambling when they find the ring they want. This makes my job is a little simpler. I only need to concern myself with the chances of finding their ring.

What I wanted to know the answers to three questions (I am assuming that they don't have the ring that would stop them even gambling for the one they want):

1) What is the percentage chance that I'll find the first ring?

    This is the question that I've answered previously. It is the chance that I'll find normal unique after N gambles.

2) What is the percentage chance that I'll find the second ring?

       This will depend on if they have the previous ring or not. If they do, then it's the same answer as in Question 1 above, if not then we'll have to look at it more closely.

3) What is the percentage chance that I'll find the third ring?

    If they have the two previous, then it's back to the answer to Question 1. If they either of the two previous then it's the answer to Question 2. If not, then we need a closer look.

Let's analyze the process a little closer. We have N repeated trials of the same act (gambling for the item). Each gamble is independent from the previous. Each gamble can either be a success or a failure (unlike the set item case). This kind of problem is called a binomial experiment and fortunately the solution is very well understood (and little derivation on my part once I recognize that this was the problem I had).

Image

Where "a" is the number of successful rolls we have. Note however that the binomial formula above leaves the possiblilty for 4 or more successful gambles. We know from our problem that this isn't the case. So we need to think about this a little.

P(3) is the probability that we get 3 success ring gambles. P(4) is the probability that we get 4, but we are stopping at 3. So P(4) would actually be added to P(3) to give the true probability that we end up with 3 rings. If we make N gambles, we are going have probabilities that range from P(1) to P(N). The ones we care about (for 3 rings) is all the P(a>2) This leads to:

Image

Now, I could just brute force my way ahead and code the above into my program and be done with it. However, it is possible to simplify this down for our specific P(2) and P(3). It's a fair amout of work, but the first step is factoring out an N!/(N-3)! then noticing what's left over and working out a formula for it. This results in the two coded equations for P(2) and P(3) as functions of N.

Image

Image

So now if we know how many rings they need to gamble for total to get the ring they want, and we know the number of gambles, we have the percentage we need.

But what about the other way around? We're also interested in finding the number of gambles needed to get a particulr percentage chance. If we take a look at the original form for Pt(3) we'll see something important. Notice that N is contained in the power for Ps and Pf . Rember that anything over a power of 5 does not have a "closed form" solution. It's not like with the quadratic formula. We don't have a algebraic way to go from P to N. This leaves us with two options. The first, scrap the idea of going from given P finding N. The second is to do it analytically.

The second option is viable becaue of two facts. The first is that after about PN=304(2)=99.9% and PN=370(3)=99.9%. Well this gives me an upper bound to the number of itereations I have to look at. As far as computations go 370 isn't that high. Now we need an initial guess. A good place to start is that N is always greater than P. If we want P=50%, then N=50 will always be below the correct answer.

I have no intention of "Brute Forcing" my way though this and write a loop that check all the answers between N=P and N=370. That would be a waste of time and computational talent. I'm going to use what's called "The Secant Method" for finding roots. It's not that hard and any introduction to numerical analysis will have it. I chose this method over the Newton's Method because the derivates for our problem are very long (not hard, just long), even though Secant requires two initial values.

Basically we solve the fuction f(x)=0 for x. We do this by iteration until the difference between two calculations is significantly small (I used 0.005). The formula for calculating the next value of x  also known as (xn+1) is:

Image

It's Over

Well, we are finally done. You probably know more than you wanted about how this program calculates the values. We had to work pretty hard, but we made it. I will not claim that everything here is perfect, however it's all thought out and holds up well under testing.