Chess by the numbers
What is perft?
Perft — short for performance test — counts every legal sequence of moves from a position down to a fixed depth. From the starting position the counts are 20, 400, 8,902 and 197,281 for one to four moves. Chess programmers compare their own counts with these to make sure their move generator has no bugs.
The table
The numbers below also say how many of the sequences end with a capture, an en passant capture, castling, a promotion, a check or a checkmate.
| Depth | Games | Captures | En passant | Castles | Promotions | Checks | Mates |
|---|---|---|---|---|---|---|---|
| 1 | 20 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | 400 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | 8,902 | 34 | 0 | 0 | 0 | 12 | 0 |
| 4 | 197,281 | 1,576 | 0 | 0 | 0 | 469 | 8 |
| 5 | 4,865,609 | 82,719 | 258 | 0 | 0 | 27,351 | 347 |
| 6 | 119,060,324 | 2,812,008 | 5,248 | 0 | 0 | 809,099 | 10,828 |
| 7 | 3,195,901,860 | 108,329,926 | 319,617 | 883,453 | 0 | 33,103,848 | 435,767 |
| 8 | 84,998,978,956 | 3,523,740,106 | 7,187,977 | 23,605,205 | 0 | 968,981,593 | 9,852,036 |
| 9 | 2,439,530,234,167 | 125,208,536,153 | 319,496,827 | 1,784,356,000 | 17,334,376 | 36,095,901,903 | 400,191,963 |
The firsts
Read down the columns and you find when each rule first comes into play: the first captures and checks at depth 3, the first checkmates at depth 4 (the eight versions of the Fool’s Mate), the first en passant capture at depth 5, the first castling at depth 7 and the first promotion at depth 9.
How it is computed
The idea fits in a few lines: generate every legal move, play it, count everything below it, take it back.
perft(depth):
if depth = 0: return 1
total = 0
for each legal move:
make the move
total += perft(depth − 1)
unmake the move
return total
Because the count is exact, a single missing or extra move anywhere — a forgotten en passant, an illegal castling through check — changes the total. Programmers also test tricky positions full of castling rights, pins and promotions, the best known of which is nicknamed “Kiwipete”.
On this site
The map is perft drawn as a picture: around the position you are looking at, its rings hold the games of depth 1 to 4. The ladder in the side panel lists the counts up to depth 15 and counts depth 5 live in your browser.