Thursday, June 7, 2012

Risk simulation: attacker vs defender

Risk is a very famous strategy board game. In the game, you conquer your opponent's territories by attacking them with armies. However, you can lose them in the attempt. In order to represent this uncertainty, the game is played with dice.

Quoting Wikipedia, these are the rules for attacking a territory:

When it's a player's turn to attack, he or she can only attack territories that are adjacent or connected by a sea-lane to his or her own territory. A battle's outcome is decided by rolling die. The attacking player attacks with one, two, or three armies, rolling a corresponding one, two or three dice. At least one army must remain behind in the attacking territory not involved in the attack, as a territory may never be left unoccupied. Before the attacker rolls, the defender must choose to resist the attack with either one or two armies (using at most the number of armies currently occupying the defended territory) by rolling one or two dice. Each player's highest die is compared, as is their second-highest die (if both players roll more than one). In each comparison, the highest number wins. The defender wins in the event of a tie. With each die comparison, the loser removes one army from his territory from the game board. Any extra dice are disregarded and do not affect the results.

I've made a Python script that simulates a single attack. Download it here.

Run the script like this:
python risk.py -a number1 -d number2 [-n number3]

Examples:
python risk.py -a 2 -d 1
Simulate a situation in which the attacker will use two armies and the defender only one.

python risk.py -a 2 -d 1 -n 1000
The same as previous, but this time the experiment will be repeated 1000 times and the program will report to the user the number of wins as well as it's percentage. Remember, the more you repeat the experiment, the more accurate the results will be.

Since I want solid information, I will simulate each one of the 6 cases 1000000 times. I takes a few seconds in my computer (Intel® Core™2 Duo CPU T5750 @ 2.00GHz × 2 and 3.0 GiB of memory).

Cases in which the defender uses a single die:

06-07-2012_1


Cases in which the defender uses two dice:

06-07-2012_2



NOTE 1: In the output of the program, a "tie" is when both players lose one army. Remember that in each die comparison, the defender will win the ties. So rolling 5 for the attacker and 5 for the defender counts as a win for the defender. What I call "ties" in the simulation would be something like this:
Attacker roll 6 and 1.
Defender roll 5 and 2.
Defender loses 1 army (6 beats 5) and attacker loses 1 army (2 beats 1).

NOTE 2: The simulation doesn't tell you if you've conquered the territory. For example, if you have 4 armies and you lose one trying to conquer the defender, you still will be able to use two armies to strike again. This situation is not contemplated. It only simulates the first attack.

In conclusion:

- When the defender uses 2 dice, there's a great chance for both opponents to lose one army (at least more than I was expecting, for me this is a surprise). Never defend with one army if you have the chance. In the past, I used two dice to make the game more dynamic, although I had doubts about if it was always the right decision. Now science tells me I have to use two armies to defend my territory. The probability of a tie is so high that it significantly whips away the security of the enemy.

- Attack the weak with all the might of your empire! If you can attack with three armies and the enemy territory is protected only by one, smash it!

- I've lived the situation in which both opponents start putting armies to threaten an enemy territory and the other one puts the same amount only to return the threat, but no one attacks (possibly in the belief that defending is more profitable than attacking). Wrong. If the situation arises, start attacking with three armies. Obviously, stop when you lose the possibility of attacking with three armies if the defender can still cast two dice.

- Don't attack with only one army.

- Always use as many dice as you can (unless you're splitting your army for some reason, but keep in mind chances are you're going to be less efficient).

These information is very poor and it won't increase significantly the chances of wining the entire game. However, it's a start. I might post more about this in the future.

No comments:

Post a Comment