Project 4: Risk Dice

CS 122 • 20 Points Total

Objectives

Overview

When you play the board game "Risk", you move armies around a map of the world and conquer new territories in battles against the other players. The battles are resolved by both sides rolling dice. Depending on the situation, the outcome may be weighted towards one side or the other, but due to the luck of the dice nothing is certain. For this project we want to determine the probabilities of success, failure, or somewhere in-between for a particular Risk battle, then graph those probabilities on a pie chart.

Identify and Explore The Problem

Let us consider the typical case in Risk: one player is attacking with three units, while the other player is defending with two units. Here are the rules for that battle and the possible outcomes:

Write a MATLAB program that calculates the probabilities of the following outcomes the the scenario described above:

The results should be displayed in a pie chart that shows the probability percentage of each outcome.

Create a Mathematical Model

Consider: the number of possible results of rolling a single D6 is 6. The probability of rolling a 1 through 6 on a D6 is 6/6, or 1.0 (100%). The probability of rolling a 1 or a 5 is 2/6, or 0.33 (33%).

The probability of any outcome for any similar problem is the number of times the outcome occurs divided by the total number of possible results.

Instead of using statistics formulas or random numbers to calculate the answer for the Risk dice, we can use the power of the computer to iterate through each possible result that can be rolled on 5D6, see which of the three outcomes that particular result falls into, and then divide each result by the total number of possible results.

Identify and Implement a Computational Method for Solving the Model

A single loop is sufficient to obtain each possible result of rolling a single die. For example, here is a MATLAB program that will calculate the probability of a 2 or a 5 being rolled on a D6:
  count = 0;
  for (d = [1:6])
    if (d==2 | d==5)
      count = count + 1;
    end
  end
  probability = count / 6

Two loops would be required to try every possible combination of rolling two dice. For each value 1..6 that the first die could roll, the second die could roll 1..6 as well, giving 36 possible combinations (62 = 36). For example, here's a program that calculates the probability of a roll on 2D6 adding up to 7:

  count = 0;
  for (d1 = [1:6])
    for (d2 = [1:6])
      if (d1+d2 == 7)
        count = count + 1;
      end
    end
  end
  probability = count / 36

We want to look at every possible combination of 5 dice being rolled. Here's an algorithm that will work:

Implement this algorithm as an M-File.


Extra Credit (up to +8 points)

For extra credit, calculate the information for and display the following additional graphs. The highest dice on each side are paired up each time, and the number of possible victories is limited by the side with the fewest dice.

Expand your original program to calculate data for all six graphs (the original scenario plus the five below). Have the graphs display on a single figure - use the subplot command to make three rows of two columns of results. Give each graph an appropriate label and legend.


Project Report

Create a report consisting of:

  1. a cover page,
  2. a project overview (with results),
  3. and printouts of all the M-files.

The project overview should contain the following information:

  1. Purpose
    Describe the purpose of your program.
  2. Approach
    Describe how you handled the different challenges that arose. Cover the following in particular - your answers can be brief, but be thorough.

  3. Issues
    Describe any significant problems you encountered and how you solved them.
  4. Results
    Include the pie graph(s) in your results.

Finally, include a printout of your M-file.