Skip to content
Adrien Hubert

Hex, against random fills.

You are red and you need a chain of red cells from the top edge to the bottom. The opponent is blue and wants left to right. It has no opening book and no idea what a bridge is. Before each move it colours every empty cell at random, thousands of times, and plays the cell that was blue in the most winning fills.

Board
4000

Click a cell, or tab to it and press Enter. Arrow keys move between cells.

0
your wins
0
its wins
—
blue wins in this share of fills
—
fills per second, last move

Note

Piet Hein invented Hex in 1942 and John Nash found it again at Princeton a few years later. A filled Hex board always has exactly one winner. Red and blue cannot both connect, because their chains would have to cross. They cannot both fail either: if red has no top-to-bottom chain, the blue cells bordering red's blocked regions form a left-to-right one. David Gale showed in 1979 that this no-draw fact is equivalent to the Brouwer fixed-point theorem.

That fact is what makes the opponent cheap. In most games a random playout is a sequence of moves, and the order matters. In Hex only the final colouring matters, since extra stones never hurt their owner. So a playout here is one shuffle. Give blue half of the empty cells (rounded up, since it is blue's turn) and red the rest, then run one flood fill from the top edge through red cells to see whether it reaches the bottom.

Each fill then credits every cell that came out blue with a win or a loss. This is the all-moves-as-first heuristic, and it is why one fill informs every candidate at once. The map on the board is that win rate per cell, rescaled so the best cell is the brightest. It plays the brightest cell.

The weakness is easy to find. Random fills assume both sides play randomly from here on, so the opponent cannot see a threat that needs one precise reply. Two red stones with two shared empty neighbours, called a bridge, can only be cut if red ignores the intrusion. Random red often does ignore it, so blue rates the cut too highly. Real Hex programs such as MoHex run the same playouts inside a search tree and add hand-proven patterns like the bridge. Raising the slider makes the estimates less noisy, not less naive.

Nash also proved that the first player wins Hex with perfect play, without giving the strategy. If the second player had a winning strategy, the first could play anywhere and then follow it, and an extra stone never hurts. Tournament play uses the swap rule to cancel that edge. This page leaves it out, so "I start" is the easier button.

Sources

  • Gale, D. (1979). The game of Hex and the Brouwer fixed-point theorem. The American Mathematical Monthly, 86(10), pages 818-827.
  • Hayward, R. B., Toft, B. (2019). Hex, the Full Story. CRC Press.
  • Brügmann, B. (1993). Monte Carlo Go. Technical report, the origin of the all-moves-as-first idea.
  • Arneson, B., Hayward, R. B., Henderson, P. (2010). Monte Carlo tree search in Hex. IEEE Transactions on Computational Intelligence and AI in Games, 2(4), pages 251-258.