Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Home Blog About Us Work Content Contact Us


�Advertisment�

RISK� Analysis
In my last blog posting, I talked about two techniques (Monte-Carlo simulation,
Markov-Chain analysis) for calculating probabilities in the game of Chutes and
Ladders.

Today, I want to take a look at the popular game of RISK�.

If you�ve not played the game, the core mechanic is based


on the rolling of dice to determine wins/losses for armies
attacking between territories. Battles occur in rounds, with an
attacking player typically rolling (up to) 3 dice, and a
defending player (up to) 2 dice. After rolling, dice are paired
up (Highest rolled attacker die against highest rolled defender
die, then next highest rolled pair if required). The highest
rolled number wins (eliminating one opponent army), with
ties resulting in a win by the defender.

Attacks by more than three armies are played in a series of


rounds. After each round, armies from the losing team are
removed from the board and the remaining pieces continue to
duel.

The fact that it is the highest then the next highest die used
for the two attacks makes a subtle twist in the probabilities.
In more than a couple of internet searches I�ve found people
have made mistakes in calculating the probabilities. So, how
should we go about calculating the true probabilities?
Following on from the last blog posting, we could do a
Monte-Carlo simulation, and roll millions of sets of dice.
The problem with this approach, however, is that we�d
only get an approximate answer, and we�d also be at the
mercy of our random number generator.

First, we�ll look at the probabilities of a single round (with


all permutations of possible attack and defence rolls). Later,
we�ll apply this learning to multiple round battles.

Since there are a small (fixed) number of dice with a finite


set out outcomes, we could create a probability tree and
work out the probabilities by hand, but being honest, this is a
lot of work, with multiple chances of making a mistake, and
incredibly tedious.
Brute force of a basic round
When an attacker has three or more armies, he can roll up to three dice. (It�s
pretty trivial to calculate that it�s always in the best interest of the attacker to roll
as many dice as possible on each round, so this will be built in the calculations
later). Similarly, it�s in the defenders interest to roll two dice where possible, and
only rolling a single defence die when there is no option.

We still, however, need to calculate the probabilities for all five possible
combinations of attack/defence combinations that could occur in a basic
round: 3v2, 3v1, 2v2, 2v1, 1v2, 1v1.

Brute Force.The simple fact is that there aren�t that many combinations to
examine. At worst case, there are only five dice rolled with a total
of 7,776 combinations (6 x 6 x 6 x 6 x 6). We can simply loop through each
possible combination of dice rolls and calculate the exact results.

There�s no reason to be a prima donna and say that brute


force is cheesy programming. Many times, the simplest
algorithm is the best.

Code for enumerating all combinations of dice is


incredibly easy to write, easy to read, and very unlikely to
contain logic errors (It honestly took me about two
minutes to write code to generate the results). If I�d tried
to do the calculation in a more "elegant" mathematical
way (or even by hand) it would have probably taken two
orders of magnitude longer to write and debug, and might
still have had a logic or calculation error left in!

It�s also not as if this piece of code is going to be executed millions of times. It�s
going to be run just once. As a good friend of mine pointed out, there are entire
sites on the internet where people argue about the most efficient and elegant
algorithms to solve certain problems, but practically, is the difference between a
great solution and a perfect solution worth the extra week it takes to develop?

Academically these algorithm discussions are noble (and don�t get me wrong,
very, very interesting); in some core cases, where performance or memory usage is
paramount, the value of an efficient and elegant algorithm more than justifies the
indulgence. But often, it is easy to forget that all you need is the answer in the
effort to engineer a graceful solution.

It's all about Horses for Courses

There is no shame in the appropriate use of a brute-force algorithm.


Algorithm
Here's the pseudo code for the case of three attackers vs. two defenders:

For Attack1 = 1 to 6

For Attack2 = 1 to 6

For Attack3 = 1 to 6

�AttackHigh = Highest (Attack1, Attack2, Attack3)

�AttackMedium = Medium (Attack1, Attack2, Attack3)

��For Defence1 = 1 to 6

��For Defence2 = 1 to 6

���DefenceHigh = Highest (Defence1, Defence2)

���DefenceLow = Lowest (Defence1, Defence2)

���Calculate_Win_Loss_Tie (AttackHigh, AttackMedium, DefenceHigh,


DefenceLow)

��Next

��Next

Next

Next

Next

That's pretty much all there is to it.


Results - Basic Battles
Here are the results of the brute force calculations for the various combinations of
dice.

Defender Rolls 2 Dice Defender Rolls 1 Die


Attack
er
Rolls
3 Attacking vs. 2 Defending 3 Attacking vs. 1 Defending
Attack Wins 2 (2890/7776) 37.17% Attack Wins (855/1296) 65.97%
Defence Wins 2 (2275/7776) 29.26% Defence Wins (441/1296) 34.03%
Attack 1 Defence
(2611/7776) 33.58%
1


2 Attacking vs. 2 Defending 2 Attacking vs. 1 Defending
Attack Wins 2 (295/1296) 22.76% Attack Wins (125/216) 57.87%
Defence Wins 2 (581/1296) 44.83% Defence Wins (91/216) 42.13%
Attack 1 Defence 1 (420/1296) 32.41%

1 Attacking vs. 2 Defending 1 Attacking vs. 1 Defending
Attack Wins (55/216) 25.46% Attack Wins (15/36) 41.67%
Defence Wins (161/216) 74.54% Defence Wins (21/36) 58.33%

Now it gets more interesting


Battles that occur when there are more than three attackers (or more than two
defenders) are more complex to calculate e.g. A battle between seven attacking
pieces and five defending pieces.
NOTE: When a player attacks, he must leave (at least) one army behind on the territory he is striking from. All my calculations are based on the
number of characters doing the actual attacking, not the number of armies on the starting square.

The tree diagram below shows the various possible outcomes for the above
example:
After the first round, the attacker could win both dice, reducing defending dice to
three. or, both the attacker and defender could each lose an army, or the attacker
could lose two armies. From the matrices above, the probabilities of these events
happening are (respectively) 2890�/�7776, 2611�/�7776, 2275�/�7776.
And, the probabilities of these events happening are based on probabilities of other
events, and so on�&

To calculate the actual probability of


the attacker being totally successful,
we have to work our way through
the tree, calculating the probability
of each event happening all the way
until we reach the leaf nodes on the
end, which will be one of the five
basic cases we calculated with brute
force.

There are many ways to calculate


the sum of the tree probabilities, but
one method that is easy to code, and
easy to read is recursion. (See an
earlier post of mine about
creating spark effects using
recusion.

We can create a
function that returns
the probability of an
attacker winning the
entire battle based
on the number of
attacker and number
of defenders
specified. This
function will add up
the three
probabilities: attack
er wins, tie,
and defender wins,
calling itself
recursively with the
adjusted parameters
for each of these
cases. This function
will call itself again
until one of the
known five basic
cases is
encountered. This
condition is the end-
case for our
recursion, and the
actual probability
for this event will
be returned by the
function which will
then ripple all the
way back to the
inital calling values.

(Yes, yes, I know


that recursion is far-
and-away from
being an optimal
way of solving this
problem. Infact it's
harder to think of a
less efficient
algorithm for
solving the
problem! But, as
above, if you only
need to run it once,
and get accurate
results the first
time, it's pretty hard
to screw up the
logic by writing the
code in a recursive
way. The entire
function is just a
few lines of code.)

Results - Complex Battles


Here are the results in tabular format for all combinations of attackers and
defenders up to 20. The percentages show the probability that the attacker will win
the territory.

� Attackers
Def
end 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
ers
41. 75. 91. 97. 99. 99. 99. 99. 99. 99. 99. 99. 100 100 100 100 100 100 100 100
1 66 42 63 15 03 67 88 96 98 99 99 99 .00 .00 .00 .00 .00 .00 .00 .00
7% 4% 7% 4% 2% 1% 8% 2% 7% 6% 8% 9% 0% 0% 0% 0% 0% 0% 0% 0%
10. 36. 65. 78. 88. 93. 96. 98. 99. 99. 99. 99. 99. 99. 99. 99. 99. 99. 99. 99.
2 61 26 59 54 97 39 66 03 01 42 70 83 915 950 975 985 993 996 998 999
0% 5% 5% 5% 9% 8% 5% 1% 1% 0% 9% 0% % % % % % % % %
02. 20. 47. 64. 76. 85. 90. 94. 96. 98. 98. 99. 99. 99. 99. 99. 99. 99. 99. 99.
3 70 60 02 16 93 69 99 68 69 11 83 34 603 781 867 928 956 976 986 992
2% 7% 5% 2% 7% 2% 4% 0% 9% 0% 9% 9% % % % % % % % %
00. 09. 31. 47. 63. 74. 83. 88. 92. 95. 97. 98. 98. 99. 99. 99. 99. 99. 99. 99.
4 68 13 49 65 82 48 37 78 98 39 20 19 932 321 605 751 857 911 950 969
8% 0% 9% 3% 9% 7% 4% 0% 2% 3% 4% 9% % % % % % % % %
00. 04. 20. 35. 50. 63. 73. 81. 87. 91. 94. 96. 97. 98. 99. 99. 99. 99. 99. 99.
5 17 91 59 86 62 77 64 84 29 62 30 37 581 498 015 401 612 768 851 912
5% 3% 4% 1% 0% 2% 0% 1% 4% 8% 4% 0% % % % % % % % %
00. 02. 13. 25. 39. 52. 64. 72. 80. 86. 90. 93. 95. 96. 98. 98. 99. 99. 99. 99.
6 04 13 37 25 67 06 00 95 76 10 52 35 611 991 065 697 180 455 663 779
5% 5% 0% 0% 5% 8% 7% 6% 4% 9% 2% 4% % % % % % % % %
00. 01. 08. 18. 29. 42. 53. 64. 72. 79. 85. 89. 92. 94. 96. 97. 98. 98. 99. 99.
7 01 13 37 14 74 33 55 29 60 98 20 61 541 929 441 644 377 949 287 547
1% 3% 4% 9% 2% 3% 3% 4% 8% 3% 5% 2% % % % % % % % %
00. 00. 05. 12. 22. 32. 44. 54. 64. 72. 79. 84. 88. 91. 94. 95. 97. 98. 98. 99.
8 00 49 35 34 40 94 55 73 64 39 41 48 857 838 318 933 242 063 715 112
3% 0% 0% 0% 5% 8% 8% 6% 1% 7% 2% 6% % % % % % % % %
00. 00. 03. 08. 16. 25. 35. 46. 55. 65. 72. 78. 83. 88. 91. 93. 95. 96. 97. 98.
9 00 25 27 61 15 77 69 39 80 00 30 98 916 227 231 772 466 861 758 482
1% 9% 7% 7% 6% 7% 3% 9% 7% 6% 3% 8% % % % % % % % %
00. 00. 02. 05. 11. 19. 28. 37. 47. 56. 65. 72. 78. 83. 87. 90. 93. 95. 96. 97.
10 00 11 07 71 82 34 67 98 99 75 38 28 676 457 696 704 284 038 504 465
0% 2% 5% 9% 8% 3% 6% 7% 4% 9% 3% 4% % % % % % % % %
00. 00. 01. 03. 08. 14. 22. 31. 39. 49. 57. 65. 72. 78. 83. 87. 90. 92. 94. 96.
11 00 05 25 91 29 69 18 17 98 39 62 76 319 447 088 248 246 848 647 169
0% 9% 5% 7% 2% 8% 7% 3% 7% 5% 9% 2% % % % % % % % %
00. 00. 00. 02. 05. 10. 17. 24. 33. 41. 50. 58. 66. 72. 78. 82. 86. 89. 92. 94.
12 00 02 79 55 94 72 33 70 37 74 65 43 140 395 284 790 869 845 457 290
0% 5% 1% 5% 2% 1% 1% 4% 5% 9% 0% 0% % % % % % % % %
00. 00. 00. 01. 04. 07. 13. 19. 26. 35. 43. 51. 59. 66. 72. 78. 82. 86. 89. 92.
13 00 01 47 72 07 96 03 73 97 33 32 78 174 515 501 172 551 547 496 107
0% 3% 5% 5% 9% 3% 9% 5% 1% 8% 8% 7% % % % % % % % %
00. 00. 00. 01. 02. 05. 09. 15. 21. 29. 37. 44. 52. 59. 66. 72. 78. 82. 86. 89.
14 00 00 29 11 87 67 95 22 94 02 11 75 827 869 884 629 102 359 273 189
0% 6% 9% 1% 5% 9% 6% 1% 3% 6% 0% 6% % % % % % % % %
00. 00. 00. 00. 01. 04. 07. 11. 17. 23. 30. 38. 46. 53. 60. 67. 72. 78. 82. 86.
15 00 00 17 74 94 14 32 88 27 98 90 72 062 788 524 248 775 065 208 040
0% 3% 9% 2% 1% 2% 1% 9% 7% 0% 4% 3% % % % % % % % %
00. 00. 00. 00. 01. 02. 05. 08. 13. 19. 25. 32. 40. 47. 54. 61. 67. 72. 78. 82.
16 00 00 11 47 35 90 48 96 75 21 86 63 204 264 681 144 605 934 055 089
0% 1% 2% 3% 1% 1% 6% 4% 3% 1% 8% 1% % % % % % % % %
00. 00. 00. 00. 00. 02. 03. 06. 10. 15. 21. 27. 34. 41. 48. 55. 61. 67. 73. 78.
17 00 00 06 31 90 08 95 87 58 54 03 62 230 572 379 516 732 956 103 068
0% 1% 7% 4% 0% 5% 8% 1% 9% 0% 4% 4% % % % % % % % %
00. 00. 00. 00. 00. 01. 02. 05. 08. 12. 17. 22. 29. 35. 42. 49. 56. 62. 68. 73.
18 00 00 04 19 62 43 92 08 27 18 25 75 265 717 844 419 302 293 300 280
0% 0% 2% 8% 0% 8% 0% 1% 3% 2% 2% 5% % % % % % % % %
00. 00. 00. 00. 00. 01. 02. 03. 06. 09. 13. 18. 24. 30. 37. 44. 50. 57. 62. 68.
19 00 00 02 13 40 02 07 83 24 67 73 89 381 804 106 031 393 043 829 637
0% 0% 5% 1% 8% 1% 3% 3% 8% 5% 6% 0% % % % % % % % %
00. 00. 00. 00. 00. 00. 01. 02. 04. 07. 11. 15. 20. 25. 32. 38. 45. 51. 57. 63.
20 00 00 01 08 27 69 51 78 80 44 06 24 457 922 251 410 145 310 746 343
0% 0% 6% 2% 9% 6% 0% 8% 3% 1% 6% 6% % % % % % % % %

Results in pictures
The above numbers
are hard to read
(and interpret), so
here they are
presented in a more
digestable way. The
picture to the left
shows the same
data, but this time
I've shaded the
matrix with colour
representing the
probability of the
attacker winning.

Where the
percentage
is >50% (advantage
to the attacker), the
square is
shaded red. Where
probability is to the
advantage of the
defender, the square
is shaded blue.

The darker the


shade of colour, the
higher the
percentage
advantage to that
player. Squares on
the leading diagonal
(where the number
of attackers and
defenders is the
same, are boxed
in yellow.

First look at results


With just a quick glance at the graph, we can notice some very interesting results,
which should help generate some tactics.

With just a small number armies on both sides, the defender has the advantage.
This is because, in the result of a tie on the dice, the defender wins.

For battles where the number of attackers and defenders is the


same 1v1, 2v2, 3v3, 4v4, then the defender has the mathematical advantage.
However, once 5v5 has been reached, advantage swings to the attacker (because the
benefit or being able to roll one extra die each round becomes more significant than
losing on a tie.

This attacker advantage widdens the larger the attacking army (you can see on the
graph above that the further to the right you go, the more the red colour seeps
below the yellow leading diaganol).

STRATEGY TIP��It's better to attack then defend. Be aggressive.

STRATEGY TIP��Always attack with superior numbers to maximize the


chances of your attack being successeful.

STRATEGY TIP��If attacking a region with the same number of armies as the
defender, make sure that you have at least five armies if you want the odds in your
favour (the more the better).

The image on the right shows the 95% confidence


limits. All attacks in the top right gray area of the
chart represent a victory for the attacker in at least
19/20 times.

Here's another way to look at the data. The chart below shows the curves for the
percentage chance of the attacker being successful. There are five different curves
corresponding to 5, 10, 15, 20, 25 defenders
Advice for defenders
At the start of each round of the game, players are given additional armies that they
can use to reinforce territories that are already owned. What is the optimal strategy
for placing these new armies?

If the aim is to defend one particular territory then, as we've already learned, safety
is in numbers. The stronger your defending force, the better your chance of
defending. But, once you've reached five armies or more on a region, an identically
sized attacking army has the advantage.
The graph on the left
shows the change
(delta) in the
percentage chance of
the defender holding
onto a territory if
being attacked by 1
attacker.

The x-axis shows the


new number of
defenders, and the y-
axis shows the change
in percentage.

As you can see,


moving
from 1 defender
to 2 defenders, results
in an increase in
percentage chance of
survival of 31%.
Increasing this
to 3 defenders adds
only another 8%
survival chance, and
increasing this
to 4 defenders another
4%.

If you're only likely to


be attacked by
singletons, it's better
to just double-up and
use your extra armies
elsewhere.
When defending
against a potential
attacking force of 5
attackers, the curve
changes. The
most "Bang for the
Buck" is obtained by
increasing the defence
force to 5 (matching
the attackers strength).

The smarter readers


will realise that these
efficiency curves
represent the gradient
of the sensitivity
curves. The most
efficient placement of
defences is where the
gradient of this curve
is the steepest.
Similarly, when
defending against a
force of 10 attackers,
the most efficient use
of reinforcement is to
get the number of
defenders to the same
level as the number of
attackers.

(The graphs start to


become more
noticeably 'spikey'
because of an
odd/even parity effect
caused by the
difference to the
attacker of having
either two or three
dice left towards the
end of the battle).
Finally, an example of
the changes in
efficiency per
defender based on
being confronted
by 15 attackers.
Again, the biggest
increase from adding a
single defender is
moving
from 14 to 15 defender
s.

STRATEGY TIP��It's better to double up defence on single territories than


increase defences on large ones.

STRATEGY TIP��The most efficient reinforcement strategy is to try and get


your regions up to the number of armies that you think your attacker will use
against you.

RISK� is a product owned by Hasbro. You can find out


more details about the product range, and buy products from
their website

You can find a complete list of all the articles here. ������Click here to
receive email alerts on new articles.

Buy me a coffee
� 2009-2013 DataGenetics

You might also like