Advertisement Jump to content
Sign in to follow this  

Win Percentage from a probability distribution of dice

This topic is 1190 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!