Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C++ please original code attached below. Problem C: OAB Simulator In this problem, start with the one-armed bandit (OAB) spinning wheel game from the
In C++ please original code attached below.
Problem C: OAB Simulator In this problem, start with the one-armed bandit (OAB) spinning wheel game from the HW2C problem. You need to re-write your code such that you can run the one-armed bandit *many* more times. The goal is to simulate the probability of winning for several different combinations of the number of wheels and the range of values on each wheel. Let w be the number of wheels to be simulated (w=4 in HW2C). "d" will remain the range of values on a wheel (1 to d). Write a function spin_the_wheels(d, w) that takes integer values d and was input parameters. Your function should return an integer 1 if all w values match from the simulated spin of the wheels. Otherwise, it should return 0. An example declaration: int spin_the_wheels(int d, int w); Now put this function within a for loop that calls the function n times and counts the number of times that the function returns 1. Call this count of the number of wins, m. Then the ratio m is a simulated estimate of the probability of winning with the given values of d and w. The larger the value of n, the better the estimate will be. The next step is to enclose this loop within another loop that varies the value of d, and then enclose both of those loops into another loop that varies the value of w. This process will produce estimates of winning for a range of values of d and w. Write a program that performs the above simulation experiment for w = 3, 4, 5, 6 and d = 9, 12, 15, ..., 27. Use n = 1,000,000 for each experiment. Your program should print the values of w and d followed by the simulated win probability and the theoretical win probability. Your program will also have to compute the theoretical win probability. You will need to divide the total number of ways to win by the total number of possible combinations. A win is defined to be the case when all w wheels have the same value. Since there are d unique values on each wheel, there are d ways in which you can win (1,1,1,1 or 2,2,2,2, etc.). The total number of combinations possible with w wheels is du = (d * d * ... * d) = pow(d,w). So, the theoretical probability of winning is d / pow(d,w). Your program will also have to compute the theoretical win probability. You will need to divide the total number of ways to win by the total number of possible combinations. A win is defined to be the case when all w wheels have the same value. Since there are d unique values on each wheel, there are d ways in which you can win (1,1,1,1 or 2,2,2,2, etc.). The total number of combinations possible with w wheels is dw = (d * d * ... * d) = pow(d,w). So, the theoretical probability of winning is d/pow(d,w). Example Output #1: w=3, d=9: Simulated probability = m = 1.23231. Theoretical Probability = 1.234578. w=3, d=12: Simulated probability = m = 0.70639. Theoretical Probability = 0.6944448. w=3, d=15: Simulated probability = m = 0.44438. Theoretical Probability = 0.4444448.Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started