Due dates:

Getting Started

Start by downloading CS101_Assign02.zip, saving it in the CS101 directory within your home directory.

Start a Cygwin Bash Shell (or Linux terminal, or MacOS terminal) and run the following commands:

cd h:
cd CS101
unzip CS101_Assign02.zip
cd CS101_Assign02

(Note that you should omit the cd h: step on Linux and MacOS.)

Using a text editor (e.g., Notepad++), open the file

CS101/CS101_Assign02/MontyHall.cpp

You will add your code to this file.

When you are ready to compile the program, in the Cygwin window (or terminal window) type the command

make

To run the program, type the command

./MontyHall.exe

The Monty Hall Problem

In this assignment, you will implement a simulation of the game show Let’s Make A Deal. In particular, you will implement a simulation which allows the user to try out strategies for the Monty Hall Problem.

In the game, the contestant would be shown a stage with three closed doors:

Milestone 1

In Milestone 1, the first of two milestones, you will simulate a single “round” in which

Here is an example run of the program (user input in bold):

Which door would you like to pick? (1-3) 3
Monty shows you a goat behind door number 2
Which door would you like to pick now? (1-3) 1
You won the car!

Another example run (user input in bold):

Which door would you like to pick? (1-3) 2
Monty shows you a goat behind door number 1
Which door would you like to pick now? (1-3) 3
You got a goat, sorry. The car was behind door 2

Deliverables for Milestone 1

The design artifact for Milestone 1 is due at the beginning class on Tuesday, Feb 7th. Make sure that you fill out the “Strategy” and “Control flow sketch” sections of the design template.

The code for Milestone 1 should be submitted to Marmoset (using the command make submit_ms1) by the end of the day on Friday, Feb 10th.

Milestone 2

In this milestone you will allow the user to play repeated games. After each game, your program should prompt the to enter 1 to continue and 0 quit.

When the user quits, the program should print a summary of how many games were played, how many games the player won, and what percentage of games the player won (to two decimal places.)

Example run showing 3 games (user input in bold):

Which door would you like to pick? (1-3) 1
Monty shows you a goat behind door number 2
Which door would you like to pick now? (1-3) 3
You won the car!
Another game? (1=yes, 0=no) 1
Which door would you like to pick? (1-3) 2
Monty shows you a goat behind door number 3
Which door would you like to pick now? (1-3) 1
You won the car!
Another game? (1=yes, 0=no) 1
Which door would you like to pick? (1-3) 3
Monty shows you a goat behind door number 2
Which door would you like to pick now? (1-3) 1
You got a goat, sorry. The car was behind door 3
Another game? (1=yes, 0=no) 0
You played 3 games
You won 2 games
You won 66.67% of the games

Deliverables for Milestone 2

There are three deliverables for Milestone 2.

First deliverable: The design artifact for Milestone 2 is due in class on Thursday, Feb 16th.

Second deliverable: Modify the program to allow the player to play multiple times as described above.

You will need to use a loop to allow the game to be repeated. Make sure that statements in your loop are properly indented.

Third deliverable: Using your program perform, experiments to test two different strategies for playing the game as follows:

  1. After Monty reveals the goat, stick with your original choice of door
  2. After Monty reveals the goat, switch doors to whichever door Monty did not reveal

For each strategy, play the game 20 times. What percentage of games did you win each time?

Using Notepad++, create an empty document and write a brief summary of your findings. Save it as a file called experiment.txt in your CS101_Assign02 folder. In the report, indicate what percentage of games you won using each strategy. If one strategy seems to be better, state which one.

Submit your code and report (the second and third deliverables) to Marmoset by running make submit_ms2. They are due by the end of day on Friday, Feb 24th.

Hints

You can allow your program to generate random integer values as follows.

Add #include <stdlib.h> and #include <time.h> to the top of the file (above or below #include <stdio.h>)

The first line of code in your main function should be

srand(time(0));

This “seeds” the random number generator to ensure that your program produces a different sequence of random numbers each time it is run.

You can generate a random integer between 1 and 3 with the code

int car = (rand() % 3) + 1;

In this code, “rand()” generates a random integer value, “(rand() % 3) constrains the random integer to the range 0-2, and adding 1 shifts the range to 1-3. In this code, the generated value is stored in the variable called car.

Grading

Milestone 1

Your grade for milestone 1 will be determined as follows:

Milestone 2

Your grade for milestone 2 will be determined as follows:

Submitting

To submit your code, make sure your MontyHall.cpp file is saved, and in the Cygwin window type one of the following commands (depending on whether you are submitting Milestone 1 or Milestone 2).

For Milestone 1:

make submit_ms1

File Milestone 2:

make submit_ms2

Enter your Marmoset username and password (which you should have received by email.) Note that your password will not be echoed to the screen. Make sure that after you enter your username and password, you see a message indicating that the submission was successful.

If the make commands above do not work, you can submit using the web interface (see the link for details).

Make sure that you check the file(s) you submitted to ensure that they are correct. See the instructions for Verifying your submission.

Important: It is your responsibility to verify that you submitted the correct files. You may receive a grade of 0 for incorrectly submitted work.