Monte Carlo Playground illustration

Monte Carlo Playground

One method, five demonstrations. Monte Carlo means answering a question by sampling at random and averaging, and this playground shows the same engine at work everywhere: darts rain onto a square to estimate π from the fraction landing in the circle, Buffon’s needles drop onto a lined floor and estimate π from the crossings, random points measure the area under a curve no formula is needed for, a thousand simulated market paths fan out to price the risk of a retirement portfolio, and a Monte Carlo tree search grows a visible game tree over six little games — tic-tac-toe and its treacherous misère twin, deep-and-narrow Nim, trap-laden Connect 3, dice-driven Pig and drawless Hex — with UCB spending playouts where they matter and exact solvers checking every verdict. Every mode drives the same pair of charts: the running estimate homing in on the true value, and the error falling on a log-log plot along the theoretical 1/√N line — quadruple the samples, halve the error.

Runs 100% in your browser — simulations are computed locally on your device.

Notes

  • The law of large numbers makes every panel work: the average of independent random samples converges to the expected value, so counting hits estimates any probability and averaging values estimates any integral.
  • Monte Carlo error shrinks as 1/√N regardless of the problem — the same square-root law governs darts, needles, portfolios and game playouts. That slow but dimension-independent rate is exactly why the method rules high-dimensional problems where grids are hopeless.
  • The game mode runs the real Monte Carlo tree search loop behind AlphaGo: descend the tree by UCB, expand one node, play out at random, back the result up. Each game exposes a different face of the algorithm — misère tic-tac-toe shows biased rollouts, Nim grows a deep needle-in-haystack tree, Connect 3 hides shallow traps, Pig adds chance nodes and Hex shows the draw-free games where MCTS shines.
  • Runs 100% in your browser — simulations are computed locally on your device.