This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Price is Right, The Big Wheel | |
#By: Cory Hofmann, Updated: 2017-12-05 | |
# | |
#Simulates the Big Wheel to determine percentage of winning based on all possible decisions | |
#Objective is to determine the probability of winning based on first spin value | |
# | |
#In all cases, Player 3 spins in the most logical way (stops if winning, spins a second time if not winning no matter what) | |
#If Player 3 ties one player, he will spin again if he has less than 0.50, otherwise go to spin-off | |
#If Player 3 ties both players, he will spin again if he has less than 0.70, otherwise go to spin-off | |
#These above two conditions are based on the odds of winning a two-man (50%) vs. three-man spin-off (33.3%) | |
# | |
#Possible decisions for Player 1 and 2: | |
#Condition A: Player 1 stays, Player 2 stays only if better | |
#Condition B: Player 1 stays, Player 2 stays if better or tied | |
#Condition C: Player 1 stays, Player 2 spins again even if better or tied | |
# | |
#Condition D: Player 1 Spins twice, Player 2 Stays only if better | |
#Condition E: Player 1 spins twice, Player 2 stays if better or tied | |
#Condition F: Player 1 Spins twice, Player 2 Spins again even if better or tied | |
n <- 1000000 #number of simulations | |
spin = matrix(nrow = n, ncol = 12) | |
for (i in c(1:n)){ | |
for (j in c(1:6)){ | |
spin[i,j] <- 0.05*sample(1:20, 1, replace = T) #Randomly draw 0.05 to 1.00 equal probability | |
} | |
score = matrix(nrow = 3, ncol = 6) | |
###Player 1 potential scores are simple, but make sure they don't spin again on 1.00 | |
if (spin[i,1] == 1.00){ | |
score[1,1:6] <- spin[i,1] | |
} else { | |
score[1,1:3] <- spin[i,1] #represents player 1 score for one spin | |
score[1,4:6] <- spin[i,1] + spin[i,2] #represents player 1 score for two spins | |
} | |
#Check to see if Player 1 busted after two spins | |
if (score[1,4] > 1.00){ | |
score[1,4:6] <- 0 | |
} | |
###Player 2 has lots of options for his spin decision tree | |
if (spin[i,3] > score[1,1] || spin[i,3] == 1.00){ | |
score[2,1] <- spin[i,3] #represents conditions A and D | |
score[2,4] <- spin[i,3] | |
} else { | |
score[2,1] <- spin[i,3] + spin[i,4] | |
score[2,4] <- spin[i,3] + spin[i,4] | |
} | |
#check if busted | |
if (score[2,1] > 1.00){ | |
score[2,1] <- 0 | |
score[2,4] <- 0 | |
} | |
if (spin[i,3] >= score[1,1] || spin[i,3] == 1.00){ | |
score[2,2] <- spin[i,3] #represents conditions B and E | |
score[2,5] <- spin[i,3] | |
} else { | |
score[2,2] <- spin[i,3] + spin[i,4] | |
score[2,5] <- spin[i,3] + spin[i,4] | |
} | |
#check if busted | |
if (score[2,2] > 1.00){ | |
score[2,2] <- 0 | |
score[2,5] <- 0 | |
} | |
#For condition C and F, Player two spins again in all scenarios except where they spin 1.00 | |
if (spin[i,3] != 1.00){ | |
score[2,3] <- spin[i,3] + spin[i,4] | |
score[2,6] <- spin[i,3] + spin[i,4] | |
} else { | |
score[2,3] <- spin[i,3] | |
score[2,6] <- spin[i,3] | |
} | |
#check if busted | |
if (score[2,3] > 1.00){ | |
score[2,3] <- 0 | |
score[2,6] <- 0 | |
} | |
###Player 3 stops if winning and spins again if not winning; spins again on ties depending on his total (see above for details) | |
for (k in c(1:6)){ #for all 6 conditions, player three will act the same | |
if (spin[i,5] > score[1,k] && spin[i,5] > score[2,k]){ | |
score[3,k] <- spin[i,5] | |
} else if (spin[i,5] == score[1,k] && spin[i,5] == score[2,k] && spin[i,5] >= 0.70){ | |
score[3,k] <- spin[i,5] | |
} else if (spin[i,5] == max(score[1,k],score[2,k]) && score[1,k] != score[2,k] && spin[i,5] >= 0.50){ | |
score[3,k] <- spin[i,5] | |
} else { | |
score[3,k] <- spin[i,5] + spin[i,6] #all other scenarios, spin the second time! | |
} | |
#check to see if Player 3 busted | |
if (score[3,k] > 1.00){ | |
score[3,k] <- 0 | |
} | |
#For all six conditions, see who is the winner! | |
temp <- c(score[1,k], score[2,k], score[3,k]) | |
if ( length(which(temp == max(temp))) == 1){ | |
spin[i,k+6] <- which.max(temp) #winner has highest score | |
} else { | |
spin[i,k+6] <- sample(which(temp == max(temp)),1) #randomly draw winner amongst ties for highest score | |
} | |
} | |
} | |
##Calculate the win percentage for each Player, for all six conditions, based on value of first spin | |
##Also, check to see scenarios of first player and second player | |
player1 = matrix(nrow = 20, ncol = 7) | |
player2 = matrix(nrow = 20, ncol = 7) | |
player3 = matrix(nrow = 20, ncol = 7) | |
for (i in c(1:20)){ | |
player1[i,1] <- i*0.05 | |
player2[i,1] <- i*0.05 | |
player3[i,1] <- i*0.05 | |
for (j in c(2:7)){ #cycles through all six conditions (A-F) | |
player1[i,j] <- 100*sum(spin[,j+5] == 1 & spin[,1] == i*0.05)/sum(spin[,1] == i*0.05) #percentage won by Player 1 for each spin | |
player2[i,j] <- 100*sum(spin[,j+5] == 2 & spin[,3] == i*0.05)/sum(spin[,3] == i*0.05) | |
player3[i,j] <- 100*sum(spin[,j+5] == 3 & spin[,5] == i*0.05)/sum(spin[,5] == i*0.05) | |
} | |
} | |
##Player 2 odds of winning based on first spin vs. Player 1, for each of the six conditions | |
player1v2_a = matrix(nrow = 21, ncol = 21) | |
player1v2_a[2:21,1] <- 0.05*c(1:20) | |
player1v2_a[1,2:21] <- 0.05*c(1:20) | |
player1v2_b = matrix(nrow = 21, ncol = 21) | |
player1v2_b[2:21,1] <- 0.05*c(1:20) | |
player1v2_b[1,2:21] <- 0.05*c(1:20) | |
player1v2_c = matrix(nrow = 21, ncol = 21) | |
player1v2_c[2:21,1] <- 0.05*c(1:20) | |
player1v2_c[1,2:21] <- 0.05*c(1:20) | |
player1v2_d = matrix(nrow = 21, ncol = 21) | |
player1v2_d[2:21,1] <- 0.05*c(1:20) | |
player1v2_d[1,2:21] <- 0.05*c(1:20) | |
player1v2_e = matrix(nrow = 21, ncol = 21) | |
player1v2_e[2:21,1] <- 0.05*c(1:20) | |
player1v2_e[1,2:21] <- 0.05*c(1:20) | |
player1v2_f = matrix(nrow = 21, ncol = 21) | |
player1v2_f[2:21,1] <- 0.05*c(1:20) | |
player1v2_f[1,2:21] <- 0.05*c(1:20) | |
for (i in c(2:21)){ | |
for (j in c(2:21)){ | |
player1v2_a[i,j] <- 100*sum(spin[,7] == 2 & spin[,1] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) / sum(spin[,1] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) | |
player1v2_b[i,j] <- 100*sum(spin[,8] == 2 & spin[,1] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) / sum(spin[,1] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) | |
player1v2_c[i,j] <- 100*sum(spin[,9] == 2 & spin[,1] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) / sum(spin[,1] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) | |
player1v2_d[i,j] <- 100*sum(spin[,10] == 2 & spin[,1] + spin[,2] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) / sum(spin[,1] + spin[,2] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) | |
player1v2_e[i,j] <- 100*sum(spin[,11] == 2 & spin[,1] + spin[,2] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) / sum(spin[,1] + spin[,2] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) | |
player1v2_f[i,j] <- 100*sum(spin[,12] == 2 & spin[,1] + spin[,2] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) / sum(spin[,1] + spin[,2] == (i-1)*0.05 & spin[,3] == (j-1)*0.05) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment