{"slug": "deciding-by-playing-at-random-monte-carlo-and-hex", "title": "Deciding by Playing at Random: Monte Carlo and Hex", "summary": "An interactive tutorial on jarroba.com's free AI course demonstrates that Monte Carlo Tree Search (MCTS) beats shallow search in 7×7 Hex: with 10,000 random games per move the machine won 61.5% (225 of 366) of games from its chosen opening cell and plays strongly, while the 100-game setting picked a different cell on a 100% result that was only 3 wins in 3 games and loses easily to a human. The lesson rests on the scale of the search — 7×7 Hex has more than 1⁰²⁰ positions, so minimax cannot run to the end — and on the UCT rule published by Levente Kocsis and Csaba Szepesvári in 2006, which concentrates simulations on promising moves and left 10,001 positions stored in the machine's tree.", "body_md": "*Note: Although this article can be read independently, it is part of a comprehensive interactive course — the table of contents for which can be found at* *https://jarroba.com/en/ai-course/**—where the entire course is available for free.*\n\nTo play Connect 4, the machine in [Playing against a machine](https://jarroba.com/en/playing-against-a-machine/) needed someone to write down how much a half-played position is worth. In many games nobody knows how to write that formula. There is another way out, and it sounds like a joke: play thousands of random games from each possible move and keep the one that wins the most.\n\nOpen the [**Game tab of the Search tool with Hex**](https://jarroba.com/tools/en/search?tab=game&game=hex&size=7&sims=10000). Hex is played on a diamond-shaped board of hexagons. Red tries to connect the top edge with the bottom one, and blue tries to connect the left edge with the right one. It cannot end in a draw: with the board full, one of them has always connected. Click **Let the machine start**.\n\nThe machine plays red, on a cell near the center. Before that, it played **10,000 random games**. Each one starts at one of the free cells, and then both sides place stones without thinking, anywhere, until one of them connects. The board shows it: the darker a cell, the more games started there, and on the five most played it writes the percentage of those games it won. With the cell it chose it won **61%**: that number is not visible on the board, because its stone covers it, and appears below. The 61 above is from another cell with a similar result, a few tenths lower: it won 216 of its 353 games, 61.2%, against 225 of 366, 61.5%, for the one the machine chose.\n\nNow choose **100** in **Random games per move** (or open [Hex with 100 random games](https://jarroba.com/tools/en/search?tab=game&game=hex&size=7&sims=100)) and click **Let the machine start** again. It plays on a different cell, next to the right edge, and says it won **100%** of the games that started there. That looks better. But it is 3 games, and it won all 3. Play one game against each: the 100-game machine is beaten without much effort; the 10,000-game one is hard.\n\n**Why minimax is not enough.** In tic-tac-toe, the machine looked at every possible game to the end. In 7×7 Hex it cannot: the tool warns that there are more than 1⁰²⁰ positions. In Connect 4 the search was cut off a few moves ahead and there the position was estimated with a hand-written formula that counted the open lines of four ( [Playing against a machine](https://jarroba.com/en/playing-against-a-machine/)). In Hex that formula is hard to write: a row of stones can be worth a lot or nothing depending on where the opponent cuts it.\n\n**What it does instead.** A single random game says little, because both sides play terribly. But if you play thousands from one move and the machine wins many more than it loses, that move leaves it in a position that is easy to win, even if nobody can explain why. This is the **Monte Carlo method**: computing something hard by repeating a random experiment many times and counting how it turns out. It was named after the Monte Carlo casino ([*Monte Carlo method*, Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)).\n\n**The tree.** Sharing the games equally among the 49 cells would spend almost all of them on bad moves. That is why the machine builds a tree as it goes, and why the method is called *Monte Carlo Tree Search* (MCTS). Each random game goes through four steps:\n\nThat is where the **10,001 positions stored in its tree** come from: one per game, plus the current one. And that is why the board is not a uniform color: the dark cells are the ones the rule has seen as promising. The rule is called UCT (for *Upper Confidence bounds applied to Trees*). It was published by Levente Kocsis and Csaba Szepesvári in 2006, the same year Rémi Coulom named the method ([*Monte Carlo tree search*, Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_tree_search)). Choosing between exploiting what already works and trying what you do not know yet is the same dilemma as in Learning from reward.\n\n**More games, better play.** I pitted the machine against itself on 7×7, with a different number of random games per move, switching who starts each time:\n\nIn both cases it knows the same about Hex: its rules and nothing else. Only the number of random games it has played changes.\n\n**A game with a history.** Hex was invented by the Danish mathematician Piet Hein in 1942, and John Nash reinvented it at Princeton around 1948. Nash proved with a very short argument that the first player can always win with perfect play, but his proof does not say how. Computers have found the way to win up to the 9×9 board; on 11×11, the tournament size, nobody knows it ([*Hex*, Wikipedia](<https://en.wikipedia.org/wiki/Hex_(board_game)>)).\n\n**From Hex to Go.** AlphaGo, the program that beat Lee Sedol at Go in 2016 by four games to one, used this same tree, guided by neural networks ([*Monte Carlo tree search*, Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_tree_search)).\n\nYou can see it in [the tool’s Go](https://jarroba.com/tools/en/search?tab=game&game=go). Click **Let the machine start**: on the 9×9 board, with 5,000 random games, it opens on E3 and wins 53% of the games that started there, and the other four most played stay between 50 and 53%. At the start of Go, as at the start of Hex, all moves win roughly the same in random games. On [the 5×5 board](https://jarroba.com/tools/en/search?tab=game&game=go&size=5) you can also see the flaw of a tree that knows nothing about the game: it chooses C2, next to the edge, and not the center. AlphaGo walked the same tree, but its neural networks told it which moves were worth trying and how much each position was worth.\n\nYou might think the best move is the one with the highest percentage. Open [the 5×5 Hex with 100 random games](https://jarroba.com/tools/en/search?tab=game&game=hex&size=5&sims=100) and click **Let the machine start**. It plays the center, which won **86%**, even though the cell above it, to the right, says **100%**.\n\nBehind the 100% there are 6 games, all won. Behind the 86%, 7, of which it won 6. With so few games, that difference is chance. The machine chooses the **most played** cell, not the one with the best percentage: the selection rule only keeps giving games to a cell while it wins, so a cell with many games has had to defend its percentage many times. A percentage computed from few cases is misleading, as happens with a small sample.\n\n*Originally published at* *https://jarroba.com* *on November 23, 2026.*\n\n[Deciding by Playing at Random: Monte Carlo and Hex](https://pub.towardsai.net/deciding-by-playing-at-random-monte-carlo-and-hex-d2f7f269aa98) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/deciding-by-playing-at-random-monte-carlo-and-hex", "canonical_source": "https://pub.towardsai.net/deciding-by-playing-at-random-monte-carlo-and-hex-d2f7f269aa98?source=rss----98111c9905da---4", "published_at": "2026-11-24 03:59:56+00:00", "updated_at": "2026-11-24 04:13:50.738599+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "ai-research"], "entities": ["jarroba.com", "Hex", "Monte Carlo Tree Search", "UCT", "Levente Kocsis", "Csaba Szepesvári", "Rémi Coulom", "Connect 4"], "also_reported_by": [], "takeaway": "In 7×7 Hex, raising MCTS simulations from 100 to 10,000 per move changed the chosen opening from a cell that won 3 of 3 games to one that won 225 of 366 (61.5%) and played far harder — a 100% rate on 3 games was noise.", "recommendation": {"advice": "Judge a move or configuration by its win rate over thousands of trials, not a handful: the 100-game Hex setting's 3-of-3 (100%) result lost to the 10,000-game setting's 225-of-366 (61.5%) in actual play.", "playbook": "evals-testing", "playbook_url": "https://wpnews.pro/playbooks/evals-testing"}, "alternates": {"html": "https://wpnews.pro/news/deciding-by-playing-at-random-monte-carlo-and-hex", "markdown": "https://wpnews.pro/news/deciding-by-playing-at-random-monte-carlo-and-hex.md", "text": "https://wpnews.pro/news/deciding-by-playing-at-random-monte-carlo-and-hex.txt", "jsonld": "https://wpnews.pro/news/deciding-by-playing-at-random-monte-carlo-and-hex.jsonld"}}