Results 1 to 11 of 11

Thread: Calculating Odds

  1. #1
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 09
    Location
    USA
    Posts
    3,823

    Calculating Odds

    I'm making a game where I need to calculate the odds of successfully completing an action.

    I've never had to do this before, so I don't know what equations to use and was hoping I could get some ideas here.

    Based on either one number, or several, I need to determine the chances of it succeeding.

    This is how I'm thinking about it right now. For each "level" a player has, the percentage that is needed to succeed decreases. So let's says they are level 1. They would need a 95% chance of succeeding. If level 2, then it's 90% and so on.

    But how would I actually come up with those odds? I plan on having the base number be the number of "items" the player has. Which starts off at 128 and goes up from there. But what number would I divide that number with to get my odds?

    Or am I going about this all wrong?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 01
    Location
    Elberfeld, IN
    Posts
    7,419

    Re: Calculating Odds

    if you know an odd in advance you could simply generate a random number between 1 and 100 and if it's equal or less than the odds, it succeeds.
    Your odds of success above for level are simple enough. 100 - (Level * 5)
    I am not sure i understand the 2nd part of your description. Give a few examples. If they have 128 items what percentage chance do you want them to have? what percentage at 129, 130? and how is this affecting the chance from the level? It sounds like you may be saying you want the 5% part to vary depending on items. Please explain better.
    John Lord, Evansville Indiana

  3. #3
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 09
    Location
    USA
    Posts
    3,823

    Re: Calculating Odds

    Quote Originally Posted by Lord Orwell View Post
    if you know an odd in advance you could simply generate a random number between 1 and 100 and if it's equal or less than the odds, it succeeds.
    Your odds of success above for level are simple enough. 100 - (Level * 5)
    I am not sure i understand the 2nd part of your description. Give a few examples. If they have 128 items what percentage chance do you want them to have? what percentage at 129, 130? and how is this affecting the chance from the level? It sounds like you may be saying you want the 5% part to vary depending on items. Please explain better.
    Yeah. I was afraid I wasn't explaining it well enough. The base number applies to the level. So if they have 128, they're one and then another number makes 2, etc. Like experience I guess.

    But your idea should work. Thanks for the info.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 09
    Posts
    326

    Re: Calculating Odds

    I'm reading between the lines here, simply because your explanation gives me little other option. I assume this is some sort of RPG where you are attempting to calculate hit percentage or something similar, right?

    If this probability (let's call it accuracy) is to be based on a single parameter, (such as the character's level), it would be pretty simple. However, the more things you want to incorporate into this system, the more difficult this problem becomes. For example, is the character using a weapon that adds or detracts to accuracy? Does the target have any defensive attributes that impact this calculation? What about environmental factors (ie, are the lights on? Is it foggy? Is this a sniper rifle in a hurricane? Is the target 10 feet away or 100 feet away?). If there are multiple bonuses or penalties, how do they offset one another?

    Now here's the kicker: every RPG has different answers to those questions, which means there is no such thing as one standard answer or system of equations.

    My suggestion is for you to find a simple curve which tends toward 0 as x approaches negative infinity and towards one as x approaches positive infinity. This is called modeling. For example, the equation [(arctan(x) / PI) + 0.5] produces such a curve. By creating an internal formula for x, such as x = αλ + β, where λ is your randomly generated number, you can modulate and offset the curve along the x-axis. Now all you need to do is augment the values of α and β according to all the things that can impact your hit probability.

    So as an exercise, I suggest you take the combined formula here, [(arctan(αλ + β) / PI) + 0.5], and create a matrix and charts in excel where you map it according to different values for α, λ, and β. That should give you a good idea of how this particular probability calculator is influenced by different factors. After that, you can make some game-based decisions as to whether this equations models your problem well enough, and if so, how much different attributes (level, weapon target, etc) should influence the different parameters.

    As a final note, arctan() is certainly not the only viable function for your purpose. There are infinitely many, including exponential decay, segments of the sin() and cos() curves, logarithmic curves, etc. The key differences between some of them is whether you ever want the probabilities to ever actually equal the limits of 1 or 0, and how quickly probabilities go up or down. Arctan() only approaches the limits, but by taking a segment of the sin wave, for example, you could actually reach 0 or 1. As to the latter question, this is where game design comes into play, and that's entirely up to you.

    Good luck.

  5. #5
    Cyberman Lord Orwell's Avatar
    Join Date
    Feb 01
    Location
    Elberfeld, IN
    Posts
    7,419

    Re: Calculating Odds

    well turning the 128 + 1 to a percentage is simple. all you have to do is subtract 128 from it.
    John Lord, Evansville Indiana

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 00
    Location
    Good Old Europe
    Posts
    3,562

    Re: Calculating Odds

    Looking at the previous answers it seemsto me your explanation isn't good enough.
    For example:
    I need to calculate the odds of successfully completing an action
    Was is this "action"? A move, making a hit or ..completing a complete level of your game?

    This is how I'm thinking about it right now. For each "level" a player has, the percentage that is needed to succeed decreases. So let's says they are level 1. They would need a 95% chance of succeeding. If level 2, then it's 90% and so on.
    These percentages should be "build" into your game, in other words you create the game that way that each player would have a 95% chance to make it through level 1 and for level 2 it would be 90%.
    But what do you want to say with: "They would need a 95% chance of succeeding."
    You can either succeed in a level or not, the 95% states that out of 100 tries to make it, you will probably make it 95 times!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 09
    Location
    USA
    Posts
    3,823

    Re: Calculating Odds

    Quote Originally Posted by opus View Post
    Looking at the previous answers it seemsto me your explanation isn't good enough.
    For example:

    Was is this "action"? A move, making a hit or ..completing a complete level of your game?


    These percentages should be "build" into your game, in other words you create the game that way that each player would have a 95% chance to make it through level 1 and for level 2 it would be 90%.
    But what do you want to say with: "They would need a 95% chance of succeeding."
    You can either succeed in a level or not, the 95% states that out of 100 tries to make it, you will probably make it 95 times!
    It's not levels they're trying to succeed on. But for each level they've achieved, their odds of succeeding should be higher.

    I guess I had that backwards, then. So if at level one, they should have a certain chance of succeeding. As they level up, their odds will increase. I don't want to start it off at 5% though because that would be very bad. So maybe the odds start at 60% and increases a certain percentage at every level.

    Does that make more sense?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  8. #8
    I don't do your homework! opus's Avatar
    Join Date
    Jun 00
    Location
    Good Old Europe
    Posts
    3,562

    Re: Calculating Odds

    Quote Originally Posted by weirddemon View Post
    ....But for each level they've achieved, their odds of succeeding should be higher.
    ??
    So the actual level has been completed(no odds needed for that) and you want to give/show percentage of succeeding in further levels?? And it should be easier for each level that has been completed(Something like : If you did manage the first class of school all classes afterwards will be easier? Your bound to end as Dr.Dr.hc...) Maybe I'm on the wrong track.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  9. #9
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 09
    Location
    USA
    Posts
    3,823

    Re: Calculating Odds

    Quote Originally Posted by opus View Post
    ??
    So the actual level has been completed(no odds needed for that) and you want to give/show percentage of succeeding in further levels?? And it should be easier for each level that has been completed(Something like : If you did manage the first class of school all classes afterwards will be easier? Your bound to end as Dr.Dr.hc...) Maybe I'm on the wrong track.
    Sort of, yeah. I'll try to detail it just a bit more.

    The player has "skill" levels. So they work on increasing those levels (separate process) and then when they want, they can try to complete a special task. Completing the task successfully awards currency. So the higher that person's skill level, the greater chance they have of completing that task and receiving the reward.

    So at skill level one, they might have a 60% chance of succeeding and that grows by a percentage each skill level they achieve.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  10. #10
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 02
    Posts
    2,301

    Re: Calculating Odds

    Growing by a fixed percentage each skill level and starting from a value of 60 is very simple: the percent chance P of succeeding given skill level L and a fixed increase of F percent per level is just
    P(L) = 60 + F*(L-1)

    (you suggested F=5 earlier I think). There are a million ways to modify this--maybe you want the odds to increase more quickly or slowly, or to level off after a while without reaching 100. Lenggries discussed some above. LordOrwell briefly mentioned how to implement an actual roll with a given percentage probability. Figuring out exactly what formulas you want in your game can be tricky. Different games do different things, though in general I personally hate it when my abilities don't work. I want them to work all the time--maybe they're weak at low levels, but I want them to work. I digress.

    The formula above is a "function", which you've probably encountered somewhere in math class. Graphing it can be informative. Wolfram Alpha is good at that; here's the F=5 version. For instance, you can tell right away that you get over a 100% chance to succeed before level 10. Maybe this is what you want, maybe it isn't; tweak things (eg. change "5" to "3") until you're happy with the results. Good luck.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  11. #11
    Cumbrian Milk's Avatar
    Join Date
    Jan 07
    Location
    0xDEADBEEF
    Posts
    2,419

    Re: Calculating Odds

    At risk of going a little off topic...

    If you ever player paper, pencil and dice style rpg you will have noticed that many things are resolved by rolling multiple dice and totalling the result. As the number of dice increase the result starts to approximate a Gaussian distribution. You can do the same with a prng very efficiantly, eg generate 4 random bytes and total them.
    W o t . S i g

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •