Deciding by Playing at Random: Monte Carlo and Hex 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. 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. To 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. Open 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 . The 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. Now 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. 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. 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 . 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: That 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. 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: In both cases it knows the same about Hex: its rules and nothing else. Only the number of random games it has played changes. 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