MonteMonty is an interactive implementation of the famous Monty Hall Problem.
The project uses Monte Carlo simulation to demonstrate the probability difference between staying and switching doors, and Monte Carlo Reinforcement Learning to train an agent to learn the optimal strategy.
The project also includes an interactive Streamlit web application where users can play the Monty Hall game themselves.
The Monty Hall Problem is a probability puzzle involving three doors:
- 🚗 One door contains a car
- 🐐 Two doors contain goats
- The player initially chooses one door
- The host opens one of the remaining doors, always revealing a goat
- The player can either Stay with their original choice or Switch to the remaining unopened door
The optimal strategy is to switch, which gives approximately a 66.7% chance of winning, compared with approximately 33.3% when staying.
MonteMonty demonstrates this result experimentally and shows how a reinforcement learning agent can learn the same strategy.
Thousands of Monty Hall games are simulated using two fixed strategies:
- Always Stay
- Always Switch
The results are compared with the theoretical probabilities.
| Strategy | Theoretical Win Rate |
|---|---|
| Stay | ~33.3% |
| Switch | ~66.7% |
As the number of simulations increases, the experimental results converge toward these theoretical probabilities.
A simple Monte Carlo reinforcement learning agent is trained to choose between:
stayswitch
The agent learns using:
- States
- Actions
- Rewards
- Q-values
- Exploration and exploitation
The Q-value represents the expected reward of taking an action in a particular state.
After training, the agent consistently learns that:
Switching has a higher expected reward than staying.
After training the reinforcement learning agent for 10,000 games, the learned policy was evaluated on a separate set of 10,000 games.
Example evaluation:
| Strategy | Win Rate |
|---|---|
| Always Stay | 33.47% |
| Always Switch | 66.44% |
| Trained RL Agent | 66.93% |
The small difference between Always Switch and the RL Agent is due to random variation from simulation.
The important result is that the RL agent learned a strategy with performance very close to the optimal Always Switch strategy.
The Streamlit application allows users to interactively play the Monty Hall Problem.
- Choose one of three doors
- The host reveals a goat behind another door
- Choose whether to Stay or Switch
- Reveal the result
- Play again
The application also displays:
- 📊 Strategy explanation
- 🧠 Learned Q-values
- 🤖 The strategy learned by the RL agent
MonteMonty/
│
├── app.py
├── requirements.txt
├── README.md
│
├── src/
│ ├── monty_hall.py
│ ├── monte_carlo.py
│ ├── rl_agent.py
│ ├── train_agent.py
│ ├── test_agent.py
│ └── compare_strategies.py
│
└── results/
├── q_values.json
├── win_rate_comparison.png
├── monte_carlo_convergence.png
└── rl_learning_curve.png