# Risk Simulator

## Inspiration

One day my family and I were playing Risk (the board game) and I was wondering what the odds were of winning, especially in the most common case of 3 attacking die vs 2 defending die.

This task may sound easy, but the thing about Risk is that the defending die get the advantage of winning all ties. Also, there are three dice rolled for the attacker but only the two higher used in combat. To add another layer to things, there are three possible outcomes: winning 0 people (and losing 2 yourself), winning 1 person (and losing 1 yourself), and winning 2 people.

At first, I tried calculating this theoretical probablility, but with the help of my dad, we could only calculate the probablity of 1 attacking die defeating 1 defending die (5/12). The problem quickly scaled after that, and as all good statisticians do when they are stuck with a situation, I resolved to make a program to find the experimental probability of winning instead.

## Creation

I originally was going to try to make this whole thing in 30 minutes, but I wanted to add a graph and more features. I wrote this code in Javascript and tried to make it object-oriented to potentially test 2vs2 or any other combination. It ended up taking me 1.2 hours to make the functionality and another 1 hour to make it look pretty and write this about page ðŸ™‚.

If you are really interested (and know some Javascript) you can always read the source code (which I tried to organize neatly and design for expansion).

## Analysis

Based on the law of large numbers, the more trials your run, the closer you should get to the true (theoretical) probability. The noise from outliers should decrease more and more over time.

That being said, I have found the probablities (of attacker winning) to be about 29% chance for 0 wins, 33.5% chance for 1 win, and 37.5% chance for 2 wins. (Again, this is 3 attacking die vs 2 defending die.) It get really laggy after a few thousand, but those results were from running to 10k.

So, from the results of this study, I learned you should always attack and agression is the best tactic (not necessarily aligning with real life).

## About the creator

I'm Elijah Mock, a web developer who likes to code and spends way too much time doing it. Feel free to contact me to leave comments about this sim or if you want to hire me to make a website or sim for you.