Advertisement

Win Percentage from a probability distribution of dice

Started by October 16, 2015 03:40 PM
2 comments, last by Desendos 9 years, 3 months ago

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.

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.

Advertisement
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];
}

Thanks guys this helped out :)

This topic is closed to new replies.

Advertisement