Let’s start this blog with a post on a fun topic: the board-game RISK: have a look at wikipedia if you would like to know more about the game, rules etc. — it is a classic.
The attached workbook contains VBA code that calculates probabilities for battle outcomes of the risk board game.
Included are the following routines:
- calc_basic_probabilities: this routines calculates the odds for battle outcomes after one roll of dice: these probabilities of course depend on how many attacking and defending armies are involved. They are fundamental for all other calculations.
- probab4: this routine calculates the probability for the transition of one battle situation (say 10 attacking and 8 defending armies) to another battle situation (say 5 attacking and 0 defending armies). The code is optimised for speed and hence can also handle battle situation with large numbers of armies.
- probab_ad4: this routine calculates the probability that, given a certain battle situation, the defending armies are wiped out and the territory is conquered by the attacking armies. Again, the code is optimised for speed and hence can handle large numbers of armies (1000 is not a problem on a normal PC)
- el_a: this routine calculates the expected loss of units for the attacker if the fight is continued until wipeout of either attacker or defender. el_d is the equivalent for the defender.
- probab_path: this function calculates the probability with which an attacker conquers several territories occupied with defending armies. It also calculates the expected attacking armies in the last territory.
- probab_path_full: same as probab_path, but also outputs probability of wipe-out and expected attacking armies for each territory on the way.
- probab_optimal: This function optimizes function probab_path with respect to the distribution of defending armies.
The analysis possible with these VBA routines allows to answer many tactical questions a RISK player may have, for instance
- Whenever the attacker has more armies than the defender, his expected losses are lower than the expected losses of the defender — therefore it seems advisable to be quite aggressive when attacking, unless other strategic considerations come into play.
- If there are no other strategic considerations, then it makes sense for the defender to leave countries that an attacker will most likely conquer with two defending armies each. While a large attacking force will still lose less armies on average than the defender with two armies in the attacked countries, the increase in expected losses for the attacking force is slightly bigger than 1 for each added “second” defense army.
- In order to optimally defend two territories (which is very common when protecting a continent) it is best to put two defending armies into the territory facing the attacker and all other available defending armies into the other territory — at least the defense is most solid that way, other more strategic considerations might ask for a different distribution.
- A reasonable rule of thumb to determine how many attacking armies are required to conquer a series of territories is the following: Armies required= 1+ #territories + 1/2* #defending armies standing alone + 3/4* #defending armies not standing alone. This formula gives the attacker approximately a 50% chance to successfully complete the conquest. In order to get more than a 90% chance, one should add twice the square root of the number of all defending armies.
While I found these insights interesting — it is good to have some definite answers — I wrote the VBA code presented here more as a kind of algorithmic puzzle: it is fairly straightforward to write slow code, but try then to optimise it: every time you are proud of your latest improvement, the next efficiency gain by a factor 2 is already waiting. So here is the challenge: whoever shows me a significantly more efficient algorithm in VBA for the function probab_ad4 will receive a honorable mention in a follow-up post and a link to where ever you want me to link to (embarrassing is fine, illegal, X-rated or virus infected not).
Attached below is a workbook with all the described macros. No warranty whatsoever is accepted, you are using this entirely at your own risk.
Attached below is a new version of the spreadsheet, which now allows one to modify the individual roll probabilities such as to accommodate a rule variation described in a comment below: the highest die roll of either party is increased by one, if the party has a “general”. If the disputed territory is a “stronghold”, the highest rolling die of the defender also gets increased by one, which might add to the effect of a defending general.
As one might expect, these additional effects change the game fundamentally and most of the observations described above lose their validity once a general is in play. For instance:
- If the defender has a general or stronghold, then the attacker will — on average — always loose more armies than the defender, even if he attacks one army with three armies of his own.
- When the defender has a stronghold or general and is trying to defend a series of territories, it will make most sense to accumulate all or almost all his defending armies in the territory with the advantage, irrespective of the order by which the territories are to be attacked.
More detailed analyses are possible with the attached tool, but as this rule variation is not very common, I will leave these to the interested reader.
Attached below is the updated workbook. No warranty whatsoever is accepted, you are using this entirely at your own risk.