1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need help developing probability calculator for a game

  1. May 26, 2013 #1
    The goal of this game is to get your opponents life points down to 0 before he gets yours down to 0. You take turns hitting each other until one persons health is at 0.

    The variables are:
    Attack (accuracy of hitting instead of missing)
    Strength (how high you can hit)
    Defense (determines opponents hit / miss ratio)
    Life points (How much health of yours is to take away.

    Now, I'm going to leave the formulas of the game out. But usually, you miss around 30% of the time.

    Out of the times you do hit, a random number is generated between 1 and your max hit determinant on your strength. A common max hit is 8, so the hitting range would be 1-8.

    Now, let's assume that we have already calculated both opponents hit/miss ratio and max hit and that we know their life points.

    The average number of hits the match will last is easy to calculate. However, my goal is to determine the probability of each player winning.

    Assume P1:
    Misses 35% of the time
    Has a hitting range of 1-8
    Life points are 60
    and P2:
    Misses 30% of the time
    Has a hitting range of 1-10
    Life points are 55

    So, P1 has to hit a total of 55 or more damage against P2 before P2 hits a total of 60 damage against P1 for P1 to win. What is the probability of P1 winning?

    I've thought about ways to do this, and I imagined that we had two overlapping probability distributions of the number of turns it would take P1 to hit 55, and P2 to hit 60.

    If we knew these distributions, we could calculate the % chance of either one of them winning with relative ease. The hard part for me is getting the probability distributions.

    Any insights on how to do this?
     
    Last edited: May 27, 2013
  2. jcsd
  3. May 27, 2013 #2

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    The model for this is a two-dimensional random walk with orthogonal absorbing boundaries. If the life points of the two players are represented as (x, y) then there is a probability distribution of how this vector changes each move. A normal analytic approach is to set up some recurrence relations to represent these transition probabilities and try to solve them using generating functions.
    In practice this can get quite messy; a more practical approach may be just to generate the numbers in software, maybe with a spreadsheet. Generate the numbers starting at (x, 0) and (0, y), working up.
     
  4. May 27, 2013 #3
    haruspex is correct.

    His suggestion is most definitely your best bet, and if you're having to ask for help with this (I mean no disrespect) your only bet.

    Please read more here.
     
  5. Jun 6, 2013 #4
    Use a computer simulation

    I once had a very complex three dimensional problem, where I needed to estimate the error distribution, which depended on the number of samples and geometrical factors. So I made an linear approximation of the geometrical factors, and scaled the distribution by k(n)/sqrt(n).
    I then applied a rather massive computer simulation, and simply calculated the average factor k(n) for n=(3,4,5,6,7,8,9). In the setup the distribution is non-linear, so I have no clue if it is even possible to calculate the k(n) analytically.
    In any case your problem should be easy to solve by a computer simulation, where you may extend simulation results by an interpolation of results as a function of an interesting parameter.

    Bo at TRNG98.se
     
  6. Jun 6, 2013 #5

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    If all 6 parameters (max hit, hit probability, life for both players) are variable and you are interested in a rough approximation ("is it a good idea to fight this player?"), I would just simulate 100 or 1000 battles and check how often P1 wins.
    This is not too time-consuming if your values are typical and if you don't have to do this for thousands of battles at once.
     
  7. Jun 6, 2013 #6
    There is a good chance that your input parameters has some distribution, so they are not all (all combinations of) equally probable. You can focus your computer run on frequent alternatives. I would then consider a direct search for most close simulations, compared to the actual case. Try a linear (multi-dimensional) interpolation between closest computer runs and the actual case.
    Bo at TRNG98.se
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Need help developing probability calculator for a game
  1. Probability: Need Help (Replies: 1)

Loading...