← Back to Ultimate Tic Tac Toe

About Ultimate Tic Tac Toe

Learn more about the game on Wikipedia.

How to Play

Objective: Win three small boards in a row (horizontally, vertically, or diagonally) on the large 3x3 meta-board.

Setup: The game is played on a 3x3 grid of smaller 3x3 Tic Tac Toe boards, creating 81 total cells.

Gameplay:

Notes on the AI

Board Representation: Internally, the game state is represented using a bitboard consisting of two u128 integers. This compact representation allows for extremely fast move generation and game state evaluation.

Search Algorithm: The AI uses Monte Carlo Tree Search (MCTS) to find good moves. MCTS works by running many random simulations from the current position to the end of the game. The algorithm builds a search tree incrementally, balancing exploration of new moves with exploitation of moves that have performed well in previous simulations.

Unlike traditional minimax algorithms, MCTS does not require a hand-crafted evaluation function. This makes it particularly well-suited for Ultimate Tic Tac Toe, where the branching factor is high and positional evaluation is complex.

Client-Side Execution: All simulations run entirely in your browser using WebAssembly. This means if you have a faster machine, more simulations will be run in the allotted time, resulting in a stronger AI opponent.

Endgame Minimax: When the game gets sufficiently close to the end, the AI switches from MCTS to minimax mode. In this mode, no simulations are run - instead, the AI calculates the optimal move directly. If the AI can win, it will play the move that guarantees victory in the fewest number of steps. If the AI knows it's in a losing position, it will play the move that delays the loss as long as possible.

I've found that simply using a minimax search with alpha beta pruning only works when the game is rather close to the end. Minimax can only search about 16-20 moves in a minute. So if the AI was using minimax from the start, it would be horribly slow, and be making essentially random moves anyway until almost the end of the game.

Back to Ultimate Tic Tac Toe