# 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.

##### 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 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 on other sites

Thanks guys this helped out :)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628293
• Total Posts
2981868

• 11
• 10
• 10
• 11
• 17