An interactive web-based visualization of the Monte Carlo Tree Search (MCTS) algorithm applied to Tic-Tac-Toe.
- Play against AI: Human plays as X, AI plays as O using MCTS
- Interactive Tree Visualization: See the MCTS search tree in real-time
- Step-by-step Execution: Step through MCTS iterations one at a time
- Full Run Mode: Run complete MCTS search with configurable iteration count
- Node Details: Click on any node to see:
- Visit count (N)
- Win value (W)
- Win rate percentage
- Board state at that node
- Tree Controls: Expand/collapse nodes, zoom, and pan
-
Open the application: Simply open
index.htmlin a web browser (no server needed!) -
Play the game:
- You play as X (first move)
- Click on any empty cell to make your move
- After your move, the AI's turn begins
-
Visualize MCTS:
- When it's the AI's turn, you can either:
- Step through iterations: Click "Step (1 Iteration)" to run MCTS one iteration at a time
- Run full search: Click "Run Full MCTS" to complete all iterations at once
- The tree updates after each iteration showing:
- Node size: Larger nodes = more visits
- Node color: Green = good for AI, Red = bad for AI
- Labels: Show move position, N (visits), W (value), and win rate
- When it's the AI's turn, you can either:
-
Explore the tree:
- Click on any node to see detailed information
- Use the tree controls to expand/collapse or reset zoom
- Pan and zoom using mouse/trackpad
-
Configure MCTS:
- Adjust "Iterations per move" to control how many iterations MCTS runs (default: 100)
- More iterations = stronger AI but slower computation
- Selection: Navigate tree using UCB1 formula to balance exploration vs exploitation
- Expansion: Add a new child node to the tree
- Simulation: Play out a random game from the new node
- Backpropagation: Update visit counts and values back up the tree
- N (Visits): Number of times this node was visited during MCTS
- W (Value): Cumulative value (wins - losses) from simulations
- Win Rate: (W/N normalized to 0-1) - probability of winning from this state
- Vanilla JavaScript (ES6+)
- D3.js for tree visualization
- HTML5/CSS3
index.html- Main HTML structurestyles.css- Application stylingtic-tac-toe.js- Game logic and rulesmcts.js- MCTS algorithm implementationtree-visualizer.js- D3.js tree visualizationapp.js- Main application controller
Works in all modern browsers that support ES6 and SVG. Tested on:
- Chrome/Edge (recommended)
- Firefox
- Safari