  ## R Project: A Game With Unusual Dice

You and your friend are bored and decide to play a game of dice. The game of craps comes to mind, but is quickly discarded since you are both familiar with the probabilities involved. Then your friend pulls out a set of three colored dice (one red, one yellow, and one green) from his pocket. These dice are unusual in that they are not numbered in the normal manner. Instead, the numbers on their six sides agree with the below table:

$$\begin{array}{|c|c|c|c|c|c|}\hline \textrm{Red} & 3 & 3 & 3 & 3 & 3 & 6\\\hline \textrm{Yellow} & 2 & 2 & 2 & 5 & 5 & 5\\\hline \textrm{Green} & 1 & 4 & 4 & 4 & 4 & 4\\\hline \end{array}$$

Your friend tells you that they came from an old board game of his -- and he doesn't recall why they are numbered this way. He also doesn't remember the rules of the original game, but suggests the following rules instead. Basically, you each pick a die to roll, and then you roll it, with the larger number winning that roll.

You are suspicious of the apparent simplicity of your friend's game, and wonder if one die rolls higher numbers than the others on average. Your friend senses your distrust and assures you that no die is any better than any other. Doing a quick calculation in your head, you acknowledge that the average of the numbers on each die is 3.5. To calm any lingering fears you have about the matter, your friend offers to let you always choose first the die with which you wish to play, and he will pick from the remaining two dice.

Let $c_i$ be one of the colors: red, yellow, or green. Let $P(c_1,c_2)$ be the probability of your winning the game if you roll the die with color $c_1$ and your friend rolls the die with color $c_2$. For example, $P(red,green)$ is the probability of your winning the game if you roll red and your friend rolls green.

1. Write three R functions red(k), yellow(k), and green(k) that simulate the sum of rolling $k$ dice of the associated color.

red = function(k) {
return(sum(sample(c(3,3,3,3,3,6),size=k,replace=TRUE)))
}

yellow = function(k) {
return(sum(sample(c(2,2,2,5,5,5),size=k,replace=TRUE)))
}

green = function(k) {
return(sum(sample(c(1,4,4,4,4,4),size=k,replace=TRUE)))
}


2. Write an R function approximated.probability.that.c1.wins(n,k,c1,c2) that simulates $n$ rolls of $k$ dice of one color $c_1$ versus $k$ dice of color $c_2$. When this function is invoked, the arguments c1 and c2 are intended to be two of the functions red, yellow, and green described previously.

approximated.probability.that.c1.wins = function(n,k,c1,c2) {
wins = sum(replicate(n,c1(k) > c2(k)))
return(wins/n)
}


3. Use the function just designed to approximate $P(c_1,c_2)$ for each possible pair of different colors, $c_1$ & $c_2$.

(Note: actual approximations produced vary...)
> approximated.probability.that.c1.wins(1000,1,red,yellow)
 0.613
> approximated.probability.that.c1.wins(1000,1,green,red)
 0.666
> approximated.probability.that.c1.wins(1000,1,yellow,green)
 0.599


4. According to your simulations, Which is the "best die" for your friend to choose if you choose to roll red, green, or yellow, respectively?

5. Does there appear to be a "best die" for you to choose to roll first? Calculate the actual probabilities that were only approximated by your simulations to confirm your answer.

6. Is this a fair game? Explain.

7. Suppose instead that you each rolled two dice of the same color, with the larger total winning the roll. Assuming that you still pick your color first, and your friend chooses his color from the remaining two -- is this new game fair? Backup your conclusion with a similar set of simulations in R, and actual calculations of the probabilities involved. In the case that the game is not fair, how should the player with the advantage choose which die to roll?

(Note: actual approximations produced vary...)
> approximate.probability.that.c1.wins(1000,2,red,yellow)
 0.433
> approximate.probability.that.c1.wins(1000,2,green,red)
 0.453
> approximate.probability.that.c1.wins(1000,2,yellow,green)
 0.413