There’s already been a question about simulating the Monty Hall Problem. This one is different. The user will play the Monty Hall Problem. Your program will play the role of the host. Montybot, if you like.
Here are the steps:
- Pick (randomly) which of the three doors hides the prize.
- Output a visual display of three doors. A simple
ABC
will do. Or three squares. Or whatever. - Receive input choosing one of the doors. This could be a mouse click on the chosen door, or a single letter input (
B
) or whatever. - Open another door. You do not open the chosen door. You do not open the door hiding the main prize. That may mean you have no choice, or it may mean that you have a choice of two. If you have a choice of two, pick one at random. Visually indicate that the door has been opened and that no prize was hidden behind it. For a program text-based input/output, this could be as simple as outputting
AB0
, to show that doorC
has been opened. Feel free to be more inventive. If you’re doing a GUI program, your choice of display is up to you. - Accept input from the user. The user may input
stick
orswitch
(or, for a GUI program, click on buttons, or use a select input, or whatever). If the user enters anything other thanstick
orswitch
, the implementation is undefined. Do whatever you want. - Output the text
You won!
orYou lost
. - Terminate the progam.
Rules:
- When you have to choose something at random, don’t worry about cryptographic randomness. Any
rand()
function will do. - The program must not cheat. The prize must be in place before the game starts. That is to say that the steps must be performed in the order given: First choose a door behind which to hide your prize, then ask the player to choose. The choice of which door to open in step 4 must happen in step 4: it is not selected in advance.
- The output in step 6 must be honest.
- This is code golf. Shortest code wins.