Monty Hall Example

Demonstrates what you can do with advanced probability
Unsplashed background img 1

I was bored, so I decided to make a Monty Hall command.

For those of you who don't know about the Monty Hall problem:

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?

If you want to actually try the problem first, I'll put the answer and the rest of this example in a spoiler box.

  • Open when you're ready

    The answer is that it is to your advantage to switch. To demonstrate this, I decided to make a little script using my probability stuff:

    command /montyhall :
      trigger:
        set {_teslas} to 0
        set {_sheeps} to 0
        set {_games} to 0
        loop integer-arg times:
          set {_1} to "sheep"
          set {_2} to "sheep"
          set {_3} to "sheep"
          $ scope
          probability:
            1 prob:
              set {_1} to "your new tesla"
            1 prob:
              set {_2} to "your new tesla"
            1 prob:
              set {_3} to "your new tesla"
          $ scope
          probability:
            1 prob:
              set {_choice} to 1
              if {_2} is "sheep":
                set {_elim} to 2
              else:
                set {_elim} to 3
            1 prob:
              set {_choice} to 2
              if {_1} is "sheep":
                set {_elim} to 1
              else:
                set {_elim} to 3
            1 prob:
              set {_choice} to 3
              if {_2} is "sheep":
                set {_elim} to 2
              else:
                set {_elim} to 1
          broadcast "You have chosen door %{_choice}%!"
          broadcast "Door %{_elim}% is a sheep and has been eliminated!"
          broadcast "Would you like to switch?"
          set {_finalchoice} to 6 - ({_choice} + {_elim})
          broadcast "You switched to %{_finalchoice}%"
          if {_%{_finalchoice}%} is "your new tesla":
            broadcast "Congratulations! You won a new Tesla!"
            add 1 to {_teslas}
          else:
            broadcast "Hey, you get a sheep!"
            add 1 to {_sheeps}
          add 1 to {_games}
        broadcast "You played %{_games}% games today"
        broadcast "You won %{_teslas}% Teslas, and %{_sheeps}% sheep"
    

    Essentially, when you do the command, you repeat an instance of the game the amount of times specified in integer-arg. Every single time you choose to switch. Every time it runs an instance of the game, it broadcasts dialogue, so beware that if you run this like 50 times, it's gonna spam your chat like crazy. At the end, it tells you how many games you played, how many Teslas (cars) you won, and how many sheep (goats) you won.

    For more info about the Monty Hall problem, go here.