How far a machine looks: the horizon effect and deciding with less
Why a machine that looks only a few moves ahead gives pieces away, how quiescence search saves it and how engines decide by looking at less. AI course 0.7.

AI from the First Bit › Level 0 — How a machine sees the world part 7 of 9
Course modules
- 1Everything is a number (yes, even your name)
- 2An image is a table of numbers
- 3A corrupted bit: how to fix it without knowing which one it is
- 4What is a model (and why a straight line already counts as one)
- 5Finding a path: an AI that learns nothing
- 6Playing against a machine: minimax and alpha-beta pruning
- 7How far a machine looks: the horizon effect and deciding with less
- 8Deciding by playing at random: Monte Carlo and Hex
- 9How a video game character decides: states, trees and scores
In Playing against a machine, the machine looked at the whole tic-tac-toe tree, but in Connect 4 it could only look a few moves ahead, and there it estimated how much the position was worth. Where it stops matters more than it seems: if it cuts off too early, it will probably play badly; if it looks too far, it either gains an advantage or wastes computation. And since searching deeper costs something, game engines use tricks to look at less and decide the same.
Try this first
Open the Game tab of the Search tool with Los Alamos chess. It is 6×6 chess without bishops, the variant in which, in 1956, a program written at Los Alamos for the MANIAC I computer was the first to play something like chess (Los Alamos chess, on Wikipedia). The machine looks 3 moves ahead, and the Quiescence search switch is on (quiescence means continuing to look until there is nothing left to capture; it is explained below).
Squares are named with a letter for the column, from a to f, and a number for the row, from 1 to 6, counting from White, which is the machine’s side. The tool’s board is seen from your side, Black, and has the letters and numbers on the edge: row 1 is at the top and column a on the right.
Press Let the machine start. It advances the pawn from square a2 to square a3 (a2–a3), and below it shows what it would have played with quiescence and without it. “The line it expects” is the move it would make and the ones it expects to come after, one from each side: its own, yours, its own. A “×” means that move captures: knight c3×b5 is “the knight on c3 captures whatever is on b5”.
| Would play | Thinks it is worth | The line it expects | |
|---|---|---|---|
| With quiescence | a2–a3 | +8 | a2–a3 a5–a4 b2–b3 |
| Without quiescence | knight b1–c3 | +102 | knight b1–c3, d5–d4, knight c3×b5 |
To rate a position, the machine counts the pieces: a pawn is worth 100, a knight 300 and a queen 900 (the tool itself says so below the table), and it subtracts yours from its own; that is why the values are in hundredths of a pawn. +102 means that, at the end of the line it expects, it thinks it will have one pawn more than you: that it will have captured one without losing anything in return. Look at the end of the line: the knight captures your pawn on b5 and that is where it stops. But that pawn is defended by your queen on c6, which would capture the knight on the next move. The machine would give a knight, worth 300, for a pawn, worth 100. It does not see it because that move lies beyond the 3 it looks at.
Move by move, from your side of the board, it looks like this:
Now move How many moves it looks ahead to 4, or open the same game looking 4 ahead, and let it start again. Without quiescence it goes wrong the other way round: it thinks the knight on c3 loses a pawn (−98), because its line ends with your knight capturing the pawn on c2, and it does not see that afterward it can capture that knight. With quiescence it goes back to a2–a3.
What just happened
This is called the horizon effect, and it was named by Hans Berliner in 1973 (Horizon effect, on Wikipedia). The machine looks to a fixed depth and there it estimates with a simple count: it adds up what each piece is worth. If the search stops right after a capture, the count says “I’m winning” or “I’m losing”, even though the obvious reply turns it around on the next move. What lies beyond the limit does not exist for it.
Quiescence search fixes it without searching deeper. On reaching the limit it does not estimate right away: it keeps looking only at captures, one after another, until it reaches a quiet position, with nothing to capture. Only then does it estimate. It costs little, because captures are few: with 3 moves, 532 positions against 509. With 4, 5,157 against 1,398: the difference grows, but it is still less than looking one more move without quiescence, which with 5 is 8,170.
The other problem is size. Open checkers (the tool’s tab is called Draughts), on a 6×6 board, and press Let the machine start. The machine looks 8 moves ahead, and the table says how many positions it cost to decide with each technique. The value and the move come out the same with all of them:
| Search | Positions looked at | Compared with pruning only |
|---|---|---|
| Minimax without pruning | 55,850 | ×11 more |
| Alpha-beta pruning | 4,915 | — |
| Pruning + move ordering | 2,984 | ×1.6 |
| Pruning + transposition table | 3,369 | ×1.5 |
| All three | 2,248 | ×2.2 |
Move ordering helps the alpha-beta pruning from 0.6. Pruning stops looking at a move as soon as it sees it is worse than another one it already has. If the best one is looked at first, all the others are discarded. The tool tries captures first and, at each level of the tree, the move that caused a cut-off last time (Alpha–beta pruning, on Wikipedia).
The transposition table is memory. The same position can be reached by different paths: if you move piece A and then B, or B first and then A, the board ends up the same. The table notes what each position already seen was worth, so as not to calculate it again (Transposition table, on Wikipedia).
The deeper the search, the more they pay off. With 12 moves, pruning alone looks at 108,860 positions and the three together at 34,524, three times fewer. In real checkers, on 8×8, there is a famous program, Chinook, from Jonathan Schaeffer’s team at the University of Alberta. In 1994 it was declared man-machine world champion, and in 2007 its team proved that checkers, played perfectly by both sides, ends in a draw (Chinook, on Wikipedia).
A real chess program puts all of this together, and more. Open full chess and press New game as Black, so that the machine, playing White, moves first. It does not look to a fixed depth but by time: it searches to 1 move, then to 2, to 3…, and uses what it learnt in each pass to order the moves of the next one. This is iterative deepening (Iterative Deepening, on the Chess Programming Wiki). When time runs out, it keeps the last complete pass. In a game in my browser, with 1 second per move, it reached 7 moves and looked at 527,669 positions; on your computer the figures will be different, because they depend on how fast it is. Besides the pruning, the move ordering, the transposition table and the quiescence search of this article, it uses tricks to prune even more, such as the null move: if the position is still good even after passing the turn, there is no need to look at it in depth (Null move pruning, on the Chess Programming Wiki).
The classic mistake
You might think the horizon is fixed by looking at more moves. It is not: it moves somewhere else. With 3 moves, the machine thinks it wins a pawn; with 4, that it loses it. And there will always be a move just behind the limit. The fix is never to stop and estimate in the middle of an exchange of pieces.
With the checkers tricks it is the other way round. They do not change the decision, only what it costs to reach it. The advantage is what is done with the time saved: searching deeper in the same time, and that does make it play better.
Try it yourself
- Open Los Alamos chess, turn off Quiescence search and play a game. Can you get the machine to leave a piece hanging? Look at the table after each of its moves: when it says “Without quiescence it would have played something else”, look at how its line ends.
Test yourself
Open Los Alamos looking 5 moves ahead and let the machine start. What would it play with quiescence and what would it play without it?
With quiescence it plays [a2–a3 / knight b1–c3 / b2–b3]. Without quiescence it plays [a2–a3 / knight b1–c3 / b2–b3], and it thinks it is worth ___.
Look at the table of what it thought, below the board.
See the answer
Answers: a2–a3, b2–b3 and 108.
Look at how its line ends without quiescence: b2–b3, knight e6–f4, knight b1–c3, d5–d4, knight c3×b5. It is the same trap as with 3 moves, two moves further on: it captures the pawn on b5 and does not see that your queen captures the knight. The horizon has moved somewhere else, but it is still there. With quiescence it goes back to a2–a3.
Test yourself
In checkers, raise the depth one at a time from 8 and let the machine start each time. At what depth does the table stop measuring minimax without pruning? How many positions does All three look at with 10?
It stops measuring it at ___ moves. With 10, the three techniques together look at ___ positions.
In the Minimax without pruning row it says “not measured: it would take too long”.
See the answer
Answers: 9 and 9025.
Without pruning, each extra move multiplies the work: with 8 it was already 55,850 positions, and with 9 the tool prefers not to wait. With the three techniques, 10 moves cost 9,025 positions, six times fewer than minimax without pruning with 8.
Further reading
- Quiescence search, on Wikipedia: quiescence search and the horizon effect, with a chess example.
- Transposition table, on Wikipedia: how positions are stored so they can be found quickly.
- Playing against a machine, from the same course: minimax and alpha-beta pruning, which this article takes as known.
- Learning from reward, from the same course: instead of writing by hand what a position is worth, let the machine learn it by playing.
“How far a machine looks: the horizon effect and deciding with less” by Ramón Invarato at jarroba.com, licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0. Registered at Safe Creative.

You may also like
How a video game character decides: states, trees and scores
Video game AI without learning: state machine, behavior tree, utility as in The Sims, and GOAP. AI course, 0.9.
Deciding by playing at random: Monte Carlo and Hex
How a machine decides when it cannot evaluate a position: thousands of random games, the Monte Carlo tree (MCTS) and Hex. AI course, 0.8.









Leave a comment