ECE-1021
HOMEWORK #5
(Last Mod: 27 November 2010 21:38:41 )
Programming Problem #5.20 (p226).
IMPORTANT NOTE: Implement the Rules of the Game!
You are writing a program that is supposed to simulate a game in order to explore the behavior of the game. Your simulation can't do this unless it implements the rules of the game with as much fidelity as possible. Your simulation should not implement some different game based upon an analysis of how you expect the game to behave. You will have only showed how a game played according to your rules behaves and not how the intended game behaves. What if your analysis is flawed? Implement the rules of the game.
To illustrate what is meant by this, let's say that you are simulating a dice game with two six-sided dice. If the player throws a seven or an eleven on the first throw, they win. To simulate the first throw staying faithful to the game you simulate rolling the first dice by picking a random integer between one and six (inclusive) and you simulate rolling the other dice by repeating this process to produce a second integer. You then add the two integers together and see if the sum is either six or eleven. What you do NOT do is analyze the expected results determining that there is a 22.2% chance of winning on the first roll and then picking a random floating point value between 0.0 and 1.0 and declare them a winner if the value is less than 0.222.
MODIFICATION: User controlled "Verbosity Level"
Many programs permit the user to control how much output is generated - or how verbose the program is. When you are developing your code and debugging it, it is generally very handy to have detailed output. But such output can greatly slow down a program when you are trying to run many millions or even billions of iterations.
Write your program so that the user can decide how game-by-game results are to be displayed by asking them for a "Verbosity Level" as follows:
Level 0 - Don't print out anything during the simulation loop - only before and after the entire simulation is run.
Level 1 - For each game, print out the game number and whether the user won or lost.
Level 2 - Level 1 info plus whether the player stayed or switched (useful for Strategy 2).
Level 3 - Level 1 and 2 info plus cumulative totals (games played, games switched and won, games stayed and won).
Level 4 - Level 1, 2, and 3 info plus cumulative statistics (% won when switched, %won when stayed).
You should find the above easy to implement and very useful in your debugging.
Note the following important points about the Verbosity Level - it ONLY affects what is output after EACH game. It has NO impact on what is printed before the first simulation starts or after the final simulation ends.
In the comments of your source code, report your results on whether a player should stay with their initial choice, switch to the other door once Monty opens a non-winning door, or whether it makes a difference. Support your results with an estimate of the probability of winning for each of the three cases based on the output of your program.
Run simulations using each of the above verbosity levels and report (in the comments of the source code) how many simulations per minute you can perform at each level (on the same computer!). To get that value, you might want to write some "wrapper code" that calls the rest of your program in a loop (with a different verbosity level on each pass) and uses the timer functions (in time.h) to measure how long it took to execute the simulation. An alternative is to simply run a large enough number of simulations that it takes at least a few minutes to perform them and sit there with a watch and time how long it takes.
The results might surprise you.