Perft calculation
To verify that a chess program correctly understands all the rules in which the pieces are allowed to move a simple test is to calculate perft values from certain positions. The perft value is calculated for a specific position to a specific depth. For the initial position the perft value to depth 1 "perft(1)" is 20 as there are 20 valid moves from the current position. Since each of the 20 positions allows the opponent to pick any move of 20 the perft(2) value is 400.Note that perft values for depths larger than 5 can take a considerable time to calculate and I strongly recommend you to calculate them one after the other so that you get a feel for how long it takes, before trying to calculate perft(9) for the initial position.
If you are using perft calculation for debugging a chess engine (which is quite likely) there is a trick you might want to use. When calculating for example perft(5) and finding that your value differs from my value you want to know why, so you can fix it. By implementing a command that generates all possible positions from the current position and then calculate the perft value with depth - 1 for the positions you'll quickly find what causes the problem. For more info on this try out the "divide" command in Sharper.
Values that I have calculated and verified with other engines:
Initial position rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
| depth | perft value |
|---|---|
| 1 | 20 |
| 2 | 400 |
| 3 | 8902 |
| 4 | 197281 |
| 5 | 4865609 |
| 6 | 119060324 |
| 7 | 3195901860 |
| 8 | 84998978956 |
| 9 | 2439530234167 |
| 10 | 69352859712417 |
Position r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -
This position is very good because it catches many possible bugs.
| depth | perft value |
|---|---|
| 1 | 48 |
| 2 | 2039 |
| 3 | 97862 |
| 4 | 4085603 |
| 5 | 193690690 |
| 6 | 8031647685 |
More positions that I've found useful for finding bugs
Position 8/3K4/2p5/p2b2r1/5k2/8/8/1q6 b - 1 67
Perft(1) = 50
Perft(2) = 279
Position 8/7p/p5pb/4k3/P1pPn3/8/P5PP/1rB2RK1 b - d3 0 28
Perft(6) = 38633283
Position rnbqkb1r/ppppp1pp/7n/4Pp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3
Perft(5) = 11139762
Position 8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -
Perft(6) = 11030083
Perft(7) = 178633661