Wednesday, August 02, 2006

Dice Wars

I have been addicted to this Flash based game Dice Wars this week. It is pretty similar to Risk. Lots of fun but tough to play just one.

I was having a trouble estimating the odds of winning any given battle, so I decided to figure them out. My probability is a little rusty, so I couldn't figure it out mathematically and had to go all Monte Carlo on this biyotch (I can remember all the the stuff with coins or balls and urns but can't figure out how to do dice).

This table shows the odds of winning a battle. The number of dice the attacker has is on top and number of dice for the defender on the side. A tie goes to the defender.

 2 3 4 5 6 7 8 1 0.8418 0.972 0.9962 0.9998 1 1 1 2 0.448 0.7798 0.9406 0.9884 0.9976 0.9998 1 3 0.1494 0.4544 0.7364 0.9056 0.9758 0.9936 0.9992 4 0.0362 0.1912 0.4482 0.7194 0.8876 0.9624 0.9904 5 0.0078 0.0606 0.2184 0.4658 0.694 0.8634 0.9538 6 0.0006 0.0158 0.0804 0.2508 0.4642 0.689 0.8432 7 0 0.0038 0.0234 0.1046 0.26 0.4714 0.6792 8 0 0.0006 0.0066 0.0384 0.12 0.2702 0.4564

For example, if you have 5 dice taking on someone with 3 you have a 90.56% chance of winning. This table is really handy when trying to figure out your strategy.

Anyway, the game is good stuff, give it a try.

via Digg

Update: The Kdice Wikispace has probabilities as well, and probably more accurate than the table above.

Anonymous said...

I have found a problem with the numbers above. You show a 100% chance of 8 dice defeating 2 dice, but it's obvious that 8 dice could roll 8,9,10,11 or 12 which is within reach of two dice. I've done the calculations and the percent should actually be .999877 which rounds to .9999 and not 1.

Fat Knowledge said...

Anon,

Wow, I am impressed! I couldn't remember how to do the math, so I just used the random number generator in my computer and ran like 1 million instances to get close to the real thing. I am not sure how accurate the numbers are, but they are more than good enough for what I wanted to use them for (figuring out what my chances of winning are on a move). I later found this site that has the probabilities, and I bet they are more accurate than mine.

Anonymous said...

Close, but it would have been more accurate to simply run for-loops for every combination and add everything up. would only take moments on a desktop to computer to churn through the tables.

eg: pseudo-code for 2 dice against 3 dice:

wins = 0;
battles = 0;

for a1 =1 to 6
for a2 = 1 to 6
for d1 = 1 to 6
for d2 = 1 to 6
for d3 = 1 to 6
battles = battles + 1
attack = a1+a2
defense = d1+d2+d3
if (attack > defense) wins = wins+1
endloop
endloop
endloop
endloop
endloop
print 'chance of 2 dice beating 3 dice is' (wins/battles * 100)

This might get a little sluggish testing 8 dice against 8 dice (2.3 billion iterations of the inner loop) so the next optimization would be to build summary tables for each number of dice, but thats another lesson ;)
Happy computing..

-Rob

Anonymous said...

eeks. i meant 2.3 trillion... so those summary tables would be useful...