# Monty Hall

See the Wikipedia page on the Monty Hall problem

The `axle.game.OldMontyHall`

object contains a model of the rules of the game.

```
import axle.game.OldMontyHall._
import spire.math.Rational
```

The models supports querying the chance of winning given the odds that the player switches his or her initial choice.

At one extreme, the odds of winning given that the other door is always chosen:

```
chanceOfWinning(Rational(1))
// res0: spire.math.Rational = 1/2
```

At the other extreme, the player always sticks with the initial choice.

```
chanceOfWinning(Rational(0))
// res1: spire.math.Rational = 1/3
```

The newer `axl.game.montyhall._`

package uses `axle.game`

typeclasses to model the game:

```
scala> import axle._
import axle._
scala> import axle.game._
import axle.game._
scala> import axle.game.montyhall._
import axle.game.montyhall._
scala> import Strategies._
import Strategies._
scala> val contestant = Player("C", "Contestant")
contestant: axle.game.Player = Player(C,Contestant)
scala> val monty = Player("M", "Monty Hall")
monty: axle.game.Player = Player(M,Monty Hall)
scala> val game = MontyHall(
| contestant, randomMove, prefixedDisplay("C")(println),
| monty, randomMove, prefixedDisplay("M")(println))
game: axle.game.montyhall.MontyHall = MontyHall(Player(C,Contestant),<function2>,<function1>,Player(M,Monty Hall),<function2>,<function1>)
scala> play(game)
C> Monty Hall Game
C> Door #1:
C> Door #2:
C> Door #3:
M> Monty Hall Game
M> Door #1: ???
M> Door #2: ???
M> Door #3: ???
C> Monty Hall did something
C> Door #1:
C> Door #2:
C> Door #3:
M> You did car placed
M> Door #1: car
M> Door #2: goat
M> Door #3: goat
C> You did door #2
C> Door #1:
C> Door #2: first choice
C> Door #3:
M> Contestant did door #2
M> Door #1: car
M> Door #2: goat, first choice
M> Door #3: goat
C> Monty Hall did reveal goat behind door #3
C> Door #1:
C> Door #2: first choice
C> Door #3: , revealed goat
M> You did reveal goat behind door #3
M> Door #1: car
M> Door #2: goat, first choice
M> Door #3: goat, revealed
C> You did stay with original choice
C> Door #1:
C> Door #2: first choice, stuck with
C> Door #3: , revealed goat
M> Contestant did stay with original choice
M> Door #1: car
M> Door #2: goat, first choice, stuck with
M> Door #3: goat, revealed
C>
C> Door #1:
C> Door #2: first choice, stuck with
C> Door #3: , revealed goat
C> You won a goat
M>
M> Door #1: car
M> Door #2: goat, first choice, stuck with
M> Door #3: goat, revealed
M> Contestant won a goat
res2: axle.game.montyhall.MontyHallState = MontyHallState(Some(PlaceCar(1)),true,Some(FirstChoice(2)),Some(Reveal(3)),Some(Right(Stay())))
```