Problem 1260. RISK board game battle simulation
Given two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to + 0.02 accuracy. The rules are given below for those unfamiliar with the game.
In the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 sixsided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:
Attacker has 10 units Defender has 10 units
Attacker rolls [6 3 2] Defender rolls [4 3]
The first comparison is attacker  6, defender  4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.
The first comparison is attacker  3, defender  3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.
This is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.
This is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker.
Example: Attacker has 3 units, Defender has 1 units.
Attacker rolls 2 die (3  1), Defender rolls 1 die.
Solution Stats
Problem Comments

6 Comments
Can you double check your values, Jeremy? I've run your sims against a couple of online Risk calculators, and they're coming up with different values for some of your test cases. For example, the one at http://recreationalmath.com/Risk/ using 10 attackers and 10 defenders comes up with 0.47993525647768026, which doesn't meet your error criteria.
Thanks, James, you were right  I generated the values myself with a Matlab script. Unfortunately I did not do enough simulations  10000 doesn't always get within 1% accuracy. Have updated them all now and rescored all solutions too.
Your solution is now the leading solution btw :)
I didn't submit a solution yet...mainly because I couldn't match up your test values and wanted to make sure that the problem wasn't on my end. (Most of the time, it is! :)
I've got a working submission now, but you'll need to check the high end of the size chart for it. As usual, Richard and Alfnie are far more clever than I.
James, you give me too much credit. The next ot best solution was a very minor tweak to Jeremy's random solver. My larger solutions, 250, find the exact solution recursively.
Solution Comments
Show commentsProblem Recent Solvers33
Suggested Problems

2697 Solvers

1880 Solvers

Number of 1s in a binary string
8489 Solvers

271 Solvers

356 Solvers
More from this Author7
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!