Sign in to follow this  
Desendos

Win Percentage from a probability distribution of dice

Recommended Posts

I have an algorithm able to calculate the probability curve of a of two Players dice rolls with nDice (Changes depending on the players circumstances.) Each player then adds their score to the Dice roll. Draws are considered draws with neither player winning. How can I compare the probability curves of the player and enemy against each other to get a Win Percentage.

 

Please ask if any more information is needed and any input is welcome.

Share this post


Link to post
Share on other sites

For each possible outcome of the roll, decide whether you're winning, and if so add the chance of that outcome happening to the total. The result is a fraction from 0 to 1 of winning.

Multiply by 100 to get a percentage.

Share this post


Link to post
Share on other sites
So player A rolls nA 6-sided dice and player be rolls nB 6-sided dice, you add up the scores and you want to know the probability of A winning, B winning and A and B getting the same score?

EDIT: In case that's what you were asking for, here's some code:
void compute_probabilities(int nA, int nB, double &prob_A_winning, double &prob_B_winning) {
  const int size = (nA + nB) * 5 + 1;
  std::vector<double> prob(size);
  prob[0] = 1.0;
  for (int i = 1; i < size; ++i)
    prob[i] = 0.0;

  for (int i = 0; i < nA + nB; ++i) {
    for (int k = size - 1; k >= 0; --k) {
      double p = 0.0;
      for (int s = std::max(k - 5, 0); s <= k; ++s)
        p += (1.0/6.0) * prob[s];
      prob[k] = p;
    }
  }
  /*
  // Debugging output
  for (int i = 0; i < size; ++i)
    std::cout << i << ' ' << prob[i] << '\n';
  */
  int threshold = 6*nB - nA;
  prob_A_winning = prob_B_winning = 0.0;
  int i;
  for (i = 0; i < threshold; ++i)
    prob_B_winning += prob[i];
  for (++i; i < size; ++i)
    prob_A_winning += prob[i];
}
Edited by Álvaro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this