{"slug": "playing-against-a-machine-minimax-and-alpha-beta-pruning", "title": "Playing Against a Machine: Minimax and Alpha-Beta Pruning", "summary": "An interactive tic-tac-toe demo from Jarroba's free AI course shows that alpha-beta pruning cuts minimax search from 549,946 positions examined on an empty board to 34,203, roughly 16 times less work while selecting the same move. The tool displays each free cell's minimax value, showing the machine's evaluation in orange and, with hints enabled, the human player's values in green — where only the center cell yields a draw. Jarroba notes tic-tac-toe contains 255,168 distinct games and 5,478 distinct boards, and that full minimax search never loses because it examines every possible reply.", "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 find a path on a map, all it takes is a good choice of the order in which to look at the cells, as [Finding a path](https://jarroba.com/?p=51292) explains. In a game there is something more: an opponent who also chooses, and who is not going to let you win. Classic search solves it with **minimax**, which always assumes the worst from the opponent, and with **alpha-beta pruning**, which reaches the same move while looking at far fewer positions.\n\nOpen the [**Game tab of the Search tool**](https://jarroba.com/tools/en/search?tab=game), on **Tic-tac-toe**. Press **Let the machine start**. It puts its X in a corner, and below it counts what it had to look at to decide: **34,203 positions looked at, with pruning**, against the **549,946 it would have looked at without pruning**, “×16 less work, and the same move”.\n\n**How to read the board.** It is an ordinary game of tic-tac-toe, with one difference: the tool shows what the machine is thinking. On each free cell it writes what playing there is worth if both of you play perfectly: who wins, if that is certain; **draw** if it ends in a tie; and a number when it is only an estimate (higher is better). A label above the board says whom those values are for. With no hints, in orange, “Values for the machine”: those are the ones it worked out to choose its move, which is why they say **it wins** or **it loses**. Those are the “draw” values of each free cell in the screenshot: the machine played in the corner, but any other first move also ended in a tie. When you play against a person, you cannot see what they are thinking; here you see what the machine has thought and why it chooses that move.\n\nNow open [the same game with the hints](https://jarroba.com/tools/en/search?tab=game&hints=true) (the **Show what each move is worth on my turn** box) and press **Let the machine start** again. The label turns green, “Values for you”, and each free cell says what that move is worth to you if both of you play perfectly: all of them say **you lose**, except the center, which says **draw** and is boxed as what would be your best move. In this example, only the center saves you from losing.\n\nA game can be drawn as a tree, like the one in the figure a little further down: at the top, the current position; below it, all the possible moves of whoever is to move; below each one, all the opponent’s replies. Each turn is a level of the tree, and so on until the game ends in a win, a loss or a draw. In tic-tac-toe, the whole tree has 255,168 distinct games ([*Game complexity*, on Wikipedia](https://en.wikipedia.org/wiki/Game_complexity)), and the tool counts 549,946 positions if everything is looked at from the empty board (many are the same board reached by different paths: there are 5,478 distinct boards).\n\n**Minimax** goes through that tree from the bottom up. The final positions are worth “win”, “loss” or “draw”. On its turn, the machine takes the move that is worth the most to it; on yours, it assumes you choose the one that is worth the least to it, that is, the best for you. That is how the value rises to the current position. The machine keeps the move that suits it best even if you always reply with what is best for you: of all its moves, the one that hurts it least. That is why it never loses at tic-tac-toe: it has looked at all the possible replies to each move.\n\nSee it in an endgame: it is just the bottom tip of the tree, because above it would be all the levels of the earlier moves. In the figure, start at the top: that board is the current position, the one the machine has in front of it. It is its turn (it plays X), and the three cells at the bottom are free. The opponent, who plays O, has two marks on the diagonal that goes down from the top right corner, and needs the one at the bottom left. If the machine blocks there (move A), the opponent has two replies left, and both end in a draw: A is worth “draw”. If it plays in either of the other two cells (B or C), the opponent completes the diagonal and wins: they are worth “loses”. Minimax keeps A.\n\n**Alpha-beta pruning** saves work without changing the result. The idea can be understood without a tree: if you already have a move that secures you a draw, and in the next one you look at, the opponent can beat you with their first reply, there is no need to look at the rest of their replies, because you are not going to choose that move anyway. In the tree, when looking at B, the opponent’s first reply already wins, and the other one, in gray, is left unlooked: with that first reply, B is already worse than the draw it gets with A, and looking at the rest is pointless. With C the same happens. On the first move from the empty board, the machine cut 13,124 branches this way, and looked at 16 times fewer positions to arrive at the same X in the corner.\n\nYou do not have to imagine that tree: the tool shows it. Open [tic-tac-toe](https://jarroba.com/tools/en/search?tab=game), press **Let the machine start** and scroll down to **The tree the machine looked at**. Every possible move comes up with what it is worth and how many positions it looked at below it. If you click one, the opponent’s replies unfold, and the branches that pruning did not get to look at appear separately, with their value worked out only to show you. **Follow the line it expects** goes through the game the machine believes will be played.\n\nWith a bigger game, the tree is too big to look at whole: Connect 4 has about 4.5 trillion distinct positions ([*Connect Four*, on Wikipedia](https://en.wikipedia.org/wiki/Connect_Four)), and going through them on every move would take too much time and too much memory. Open [Connect 4](https://jarroba.com/tools/en/search?tab=game&game=connect4) and let the machine start: now it looks only 6 moves ahead (the **depth**) and, where it cuts off, it **estimates** how much the position is worth with a score, which is what shows in the columns (numbers like −18 or 0) instead of “it wins” or “it loses”. That estimate plays the role of A*’s heuristic: a shortcut written by a person. Even so, pruning saves it a lot: 7,000 positions instead of 137,257. And the saving holds later in the game: in the screenshot, after four moves of yours, it looked at 6,567 positions instead of 130,558, and above each column it writes what it estimates playing there is worth to it.\n\nYou might think pruning is a gamble: that, by looking at less, the machine sometimes skips the best move. With alpha-beta pruning that does not happen. It only cuts the branches that, whatever they are worth, are not going to change the move it chooses, and it arrives at the same move as minimax looking at everything ([*Alpha-beta pruning*, on Wikipedia](https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning)). What does change the result is the depth: with a tree too big to look at whole, the machine plays only as well as its depth and its estimate allow.\n\n*Originally published at* *https://jarroba.com* *on November 18, 2026.*\n\n[Playing Against a Machine: Minimax and Alpha-Beta Pruning](https://pub.towardsai.net/playing-against-a-machine-minimax-and-alpha-beta-pruning-7334e3a9ffa5) 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/playing-against-a-machine-minimax-and-alpha-beta-pruning", "canonical_source": "https://pub.towardsai.net/playing-against-a-machine-minimax-and-alpha-beta-pruning-7334e3a9ffa5?source=rss----98111c9905da---4", "published_at": "2026-11-23 03:27:18+00:00", "updated_at": "2026-11-23 03:46:22.084681+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-research", "machine-learning"], "entities": ["Jarroba", "Minimax", "Alpha-Beta Pruning", "Tic-tac-toe", "Wikipedia"], "also_reported_by": [], "takeaway": "Alpha-beta pruning reached the same tic-tac-toe move as full minimax while examining 34,203 positions instead of 549,946 — about 16 times less work — because it skips branches that cannot change the chosen move.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/playing-against-a-machine-minimax-and-alpha-beta-pruning", "markdown": "https://wpnews.pro/news/playing-against-a-machine-minimax-and-alpha-beta-pruning.md", "text": "https://wpnews.pro/news/playing-against-a-machine-minimax-and-alpha-beta-pruning.txt", "jsonld": "https://wpnews.pro/news/playing-against-a-machine-minimax-and-alpha-beta-pruning.jsonld"}}