%set seed rng('shuffle'); %initial values trueState=["goat","goat","car"]; %randomize them trueState=trueState(randperm(3)); %player doesn't know what's behind any door; %set all values to NaN...

1 answer below »
Please refer pj3


%set seed rng('shuffle'); %initial values trueState=["goat","goat","car"]; %randomize them trueState=trueState(randperm(3)); %player doesn't know what's behind any door; %set all values to NaN playerState=["door","door","door"]; %query user playerChoice = questdlg('Pick a Door, any Door!', ... 'Monty Hall', ... '1','2','3','1'); %convert to numeric playerChoice=str2double(playerChoice); %mark the chosen door playerState(playerChoice)="choice"; %if player chose the car... if find(playerState=="choice")==find(trueState=="car") %host selects randomly between the other two doors remainingDoors=find(trueState=="goat"); openedDoor=remainingDoors(randi(2)); playerState(openedDoor)="goat"; else %otherwise, select the other door with the goat playerState(trueState=="goat" & playerState=="door")="goat"; end %identify door opened hostChoice=find(playerState=="goat"); %identify remaining door remainingDoor=find(playerState=="door"); %ask the player if they want to switch textToAsk=['You selected Door ' num2str(playerChoice) ... '. Monty Hall opens Door ' num2str(hostChoice) ... ' and reveals a goat. Do you want to switch to Door ' ... num2str(remainingDoor) '?']; switchChoice = questdlg(textToAsk, ... 'Monty Hall', ... 'Yes','No','No'); %if the player switches, change their choice in playerState if switchChoice=="Yes" playerState(remainingDoor)="choice"; playerState(playerChoice)="door"; end %determine player's reward if find(playerState=="choice")==find(trueState=="car") waitfor(msgbox('Congratulations! You won a car!')); else waitfor(msgbox('Congratulations! You won a goat!')); end Project 3: Monty Hall For the third project, you will modify the Monty Hall code provided in lecture (monty_hall.m, Week 10 folder on CCLE) to run in the Command Window and in docked figure windows, produce images representing the state of the game at each step, and allow the player to start a new game after completing one. Save your script as pj3_.m where, as in previous assignments, is replaced by your 9-digit student ID number. Background Let’s Make a Deal was a popular game show which began in 1963; the host of the game show was named Monty Hall. On this show, like most game shows, people played games to win prizes. The Monty Hall probability puzzle, which draws its name from the game show, was never played on the show and has little to do with the show, so I won’t be discussing the show further. The Monty Hall probability puzzle first appeared in The American Statistician in 1975 but was popularized by its appearance in a reader’s letter in a column called “Ask Marilyn” in Parade magazine by Marilyn vos Savant, the woman with (at the time, at least) the highest IQ ever measured. Below is the problem. The bolded text represents the problem as originally presented in Parade (which, as discussed in lecture, is woefully underspecified), while the remaining text was added by me to clarify the rules of the game: Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice? EXTRA RULES: The host must always open a door that was not picked by the contestant. The host must always open a door to reveal a goat and never the car. The host must always offer the chance to switch between the originally chosen door and the remaining closed door. If the host has a choice of which door to open (that is, the player chose correctly and the other two doors have goats), the host will open one of the two doors with goat at random. The correct answer is that you are more likely to win the car if you switch. Specifically, if you do not switch, the probability of winning is 1 in 3, because in that case the second “Do you want to switch?” part of the game is completely ignored and the game reduces to picking the door that was originally chosen; because the probability that there is a car behind one of the three doors at the beginning of the game is 1 in 3, the probability of winning if you do not switch is 1 in 3. If you do switch, the probability of winning is 2 in 3, which is counterintuitive at first. Most people believe the probability is the same as above (1 in 3) or equal for the two doors (1 in 2). Consider that the car can be behind any of the doors at the start of the game, and the probability that the car is behind the door the player originally chose is 1 in 3. Likewise, the probability that the car is behind one of the other two doors is 2 in 3. If the car is behind the door that the player chose, then the host will open a door at random and the player will always lose if they switch. If the car is behind a door that the player did not choose, then the host is forced to open the remaining door with the goat (not chosen by the player, not containing a car) and the player will always win if they switch because they will always switch to the car. Thus, there is a 1 in 3 chance that switching will always yield a goat (car is behind the player’s door) and a 2 in 3 chance that switching will always yield a car (car is not behind the player’s door), resulting in a probability of winning if you switch in general of 2 in 3. If that was confusing, don’t worry, you don’t need to understand the solution at all to complete the project. If you still don’t believe it, you can do Extra Credit Option 2 and prove it to yourself. Part 1: Trying again (3 points) Your first task is to allow the player to repeat the game if they wish. This requires two additions: 1. Put the entire game in a while loop (1 point). You may put the rng('shuffle'); command inside or outside of the loop, it makes no difference 2. Add an extra query to the end of the game (inside the loop) asking the player if they would like to play again (2 points). If the player says “No”, the loop should exit (see details on input format below. Although I don’t like using break myself, feel free to use it here. Part 2. Adapting the game for MATLAB Online (5 points) If you try running my example code in MATLAB Online, you’ll see that MATLAB Online’s treatment of dialog boxes is very clunky and ugly. It also makes the displays harder to see. Using the Command Window to input and output text is much sleeker and is fully compatible with the online platforms. For Part 2, you’ll adapt the game to run through the Command Window, using the input function to take in user input (don’t forget the extra ‘s’ argument to store the result as a string) and disp, sprintf, or fprintf to display any extra output. Specifically: • Change dialog boxes to Command Window input & output (1 point) • Add Type 1, 2, or 3, then press Enter to the text when choosing a door (1 point) o Only the single characters 1, 2, or 3 should allow the experiment to continue • Add Type Y for Yes or N for No, then press Enter when asking to switch and when asking to play again (1 point each) o Your code should be case insensitive, accepting y or Y, n or N o Only the single characters y, Y, n, or N should allow the experiment to continue (or terminate, if n or N is given at the end) • If an invalid input is provided, create a new input prompt with the text Invalid input; please try again. (1 point) o After each valid input, clear the command window with clc Technical point: You can still use desktop MATLAB for this project; it does not need to be done in MATLAB Online. If you do use desktop MATLAB, use this command to dock figures within MATLAB: f=figure('WindowStyle','docked’); Comment this line out when you submit your project; it’s not worth points, but it will make grading easier. Part 3: Adding pictures (4 points) Your second task is to add pictures to the game. The pictures to be used are in the Week 10 folder on CCLE: • doors.png: The doors in the game. The objects behind the doors (goat or car) will be inserted into the doors. • goat.png: The goat • car.png: The car The following outline describes the desired behavior, or “script” of the game. Pay close attention to all steps and make sure that your code follows this script exactly! 1. The “Run” button is pressed and the game begins. 2. The image of the doors is displayed (1 point), and the player is asked which door they would like to select. 3. The player makes their selection: 1, 2, or 3. 4. The image is updated by inserting a goat into the door that the host (played by the computer) selects. The image should be resized to fit within the door; see the Bowser and Luigi code at the end of the Image Manipulation lecture for an example. See the Bond code in the same lecture for an example of inserting one image into another. None of the blue inside of the door should be visible once the image is inserted, and at least one pixel of the black outline of the door should remain on the outside of the image after insertion. 5. The new image of the doors is displayed (1 point), showing the goat, and the player is asked if they would like to switch. 6. The player makes their selection: Y or N. 7. The image is updated by inserting the prize behind the player’s chosen door: the original door if the player did not switch, and the door the player switched to if they switched. This image will either be the goat or the
Answered Same DayDec 07, 2021

Answer To: %set seed rng('shuffle'); %initial values trueState=["goat","goat","car"]; %randomize them...

Nishchay answered on Dec 07 2021
132 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here