Sulprobil
Search…
Game of Risk
"The happiness of the drop is to die in the river." [Imam Al-Ghazali]
Most of us know the strategic board game Risk.
But do you also know which chances you have to win an attack if you have 15 armies on your country and the defending neighbour has 11?
Now, with the new (current) rules of the game you could attack with 14 of your 15 armies and you would have a chance of about 79% to win: (see blue circle in the bottom matrix)
I have applied a conditional format which colours the back in red for chances of about 50% and below, the colour is yellowish for chances between 50% and 75% and becomes green if your chances are higher than 75%.
Please notice that both matrices should theoretically be identical for the first two columns. Small differences are due to "incomplete" randomness of the finite Monte Carlo run with 10,000 tries.
The code:
Please note that you should also include the SystemState class.
Please read my Disclaimer.
1
Const GCMonteCarloRuns = 10000
2
3
Sub Schedule()
4
'Calculate chances for an attacker at the game of risk for both the original
5
'version (both attacker and defender roll up to 3 dice) and the new version
6
'(attacker rolls up to 3 dice, defender only up to 2).
7
'Calls parametrized sub Calculate_Chances twice.
8
'Reverse(moc.liborplus.www) V0.1 30-Sep-2012
9
Dim ws As Worksheet
10
'Include SystemState class from http://sulprobil.com/html/systemstate.html
11
Dim state As SystemState
12
Application.StatusBar = False
13
Set state = New SystemState
14
15
'Preparation
16
Set ws = Sheets("Chances")
17
ws.Cells.ClearContents
18
19
Call Calculate_Chances("Old Version: Both Attacker and defender roll up to" & _
20
" 3 dice.", 1, 3)
21
Call Calculate_Chances("New Version: Attacker rolls up to 3 dice, defender" & _
22
" only up to 2.", 23, 2)
23
24
End Sub
25
26
Sub Calculate_Chances(sTitle As String, _
27
lOutputRow As Long, _
28
lMaxDefenderArmies As Long)
29
'Calculate chances for an attacker at the game of risk.
30
'This sub calculates the chances for a matrix of 2 to 20 attacking armies
31
'against 1 to 20 defending armies.
32
'Reverse(moc.liborplus.www) V0.1 30-Sep-2012
33
Dim i As Long
34
Dim j As Long
35
Dim k As Long
36
Dim m As Long
37
Dim lAttackerDice As Long
38
Dim lAttackerThrow As Long
39
Dim lAttackerResult(1 To 3) As Long
40
Dim lAttackerWins As Long
41
Dim lDefenderDice As Long
42
Dim lDefenderThrow As Long
43
Dim lDefenderResult(1 To 3) As Long
44
Dim ws As Worksheet
45
46
Dim state As SystemState
47
Application.StatusBar = False
48
Set state = New SystemState
49
50
With Application.WorksheetFunction
51
'Preparation
52
Set ws = Sheets("Chances")
53
ws.Cells(lOutputRow, 1) = sTitle
54
ws.Cells(lOutputRow + 1, 1) = "Attacker armies \ Defender armies"
55
For i = 2 To 20
56
Application.StatusBar = "Calculating " & i & " attackers for " & sTitle
57
For j = 1 To 20
58
ws.Cells(i + lOutputRow, 1) = i
59
ws.Cells(1 + lOutputRow, j + 1) = j
60
lAttackerWins = 0
61
For k = 1 To GCMonteCarloRuns
62
lAttackerDice = i - 1 'One army needs to occupy the land and
63
'cannot be used to attack
64
lDefenderDice = j
65
Do While lAttackerDice > 0 And lDefenderDice > 0
66
lAttackerThrow = lAttackerDice
67
If lAttackerThrow > 3 Then lAttackerThrow = 3
68
lDefenderThrow = lDefenderDice
69
If lDefenderThrow > lMaxDefenderArmies Then
70
lDefenderThrow = lMaxDefenderArmies
71
End If
72
'Roll the dice
73
For m = 2 To 3
74
lAttackerResult(m) = 0
75
lDefenderResult(m) = 0
76
Next m
77
For m = 1 To lAttackerThrow
78
lAttackerResult(m) = Int(1 + Rnd * 6)
79
Next m
80
For m = 1 To lDefenderThrow
81
lDefenderResult(m) = Int(1 + Rnd * 6)
82
Next m
83
'Sort results
84
If lAttackerResult(1) < lAttackerResult(2) Then
85
If lAttackerResult(1) < lAttackerResult(3) Then
86
If lAttackerResult(2) < lAttackerResult(3) Then
87
'3-2-1
88
m = lAttackerResult(1)
89
lAttackerResult(1) = lAttackerResult(3)
90
lAttackerResult(3) = m
91
Else
92
'2-3-1
93
m = lAttackerResult(1)
94
lAttackerResult(1) = lAttackerResult(2)
95
lAttackerResult(2) = lAttackerResult(3)
96
lAttackerResult(3) = m
97
End If
98
Else
99
'2-1-3
100
m = lAttackerResult(1)
101
lAttackerResult(1) = lAttackerResult(2)
102
lAttackerResult(2) = m
103
End If
104
Else
105
If lAttackerResult(1) < lAttackerResult(3) Then
106
If lAttackerResult(2) < lAttackerResult(3) Then
107
'3-1-2
108
m = lAttackerResult(1)
109
lAttackerResult(1) = lAttackerResult(3)
110
lAttackerResult(3) = lAttackerResult(2)
111
lAttackerResult(2) = m
112
End If
113
Else
114
If lAttackerResult(2) < lAttackerResult(3) Then
115
'1-3-2
116
m = lAttackerResult(2)
117
lAttackerResult(2) = lAttackerResult(3)
118
lAttackerResult(3) = m
119
End If
120
End If
121
End If
122
If lDefenderResult(1) < lDefenderResult(2) Then
123
If lDefenderResult(1) < lDefenderResult(3) Then
124
If lDefenderResult(2) < lDefenderResult(3) Then
125
'3-2-1
126
m = lDefenderResult(1)
127
lDefenderResult(1) = lDefenderResult(3)
128
lDefenderResult(3) = m
129
Else
130
'2-3-1
131
m = lDefenderResult(1)
132
lDefenderResult(1) = lDefenderResult(2)
133
lDefenderResult(2) = lDefenderResult(3)
134
lDefenderResult(3) = m
135
End If
136
Else
137
'2-1-3
138
m = lDefenderResult(1)
139
lDefenderResult(1) = lDefenderResult(2)
140
lDefenderResult(2) = m
141
End If
142
Else
143
If lDefenderResult(1) < lDefenderResult(3) Then
144
If lDefenderResult(2) < lDefenderResult(3) Then
145
'3-1-2
146
m = lDefenderResult(1)
147
lDefenderResult(1) = lDefenderResult(3)
148
lDefenderResult(3) = lDefenderResult(2)
149
lDefenderResult(2) = m
150
End If
151
Else
152
If lDefenderResult(2) < lDefenderResult(3) Then
153
'1-3-2
154
m = lDefenderResult(2)
155
lDefenderResult(2) = lDefenderResult(3)
156
lDefenderResult(3) = m
157
End If
158
End If
159
End If
160
'Analyze result and reduce armies
161
For m = 1 To 3
162
If lAttackerResult(m) > 0 And lDefenderResult(m) > 0 Then
163
If lAttackerResult(m) > lDefenderResult(m) Then
164
lDefenderDice = lDefenderDice - 1
165
Else
166
lAttackerDice = lAttackerDice - 1
167
End If
168
Else
169
Exit For
170
End If
171
Next m
172
Loop
173
If lAttackerDice > 0 Then
174
lAttackerWins = lAttackerWins + 1
175
End If
176
Next k
177
ws.Cells(i + lOutputRow, j + 1) = lAttackerWins / GCMonteCarloRuns
178
Next j
179
Next i
180
End With
181
End Sub
Copied!
Chances_at_Game_of_Risk.xlsm
59KB
Binary
Chances_at_Game_of_Risk.xlsm
Last modified 1yr ago
Copy link