Professional Documents
Culture Documents
RISK Analysis: Last Blog Posting
RISK Analysis: Last Blog Posting
�
�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.
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.
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.
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.
For Attack1 = 1 to 6
For Attack2 = 1 to 6
For Attack3 = 1 to 6
��For Defence1 = 1 to 6
��For Defence2 = 1 to 6
��Next
��Next
Next
Next
Next
�
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%
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�&
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.
� 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.
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.
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��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).
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.
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