A few positions to test movegen

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

A few positions to test movegen

Post by mar »

Here is a list of a few artifical positions to test some of the common pitfalls of move generators.
Each position appears twice with colors reversed.
I think it may be useful to others too.
Of course passing the test doesn't mean the movegen is bug-free.

avoid illegal en passant capture:
8/5bk1/8/2Pp4/8/1K6/8/8 w - d6 0 1 perft 6 = 824064
8/8/1k6/8/2pP4/8/5BK1/8 b - d3 0 1 perft 6 = 824064
en passant capture checks opponent:
8/8/1k6/2b5/2pP4/8/5K2/8 b - d3 0 1 perft 6 = 1440467
8/5k2/8/2Pp4/2B5/1K6/8/8 w - d6 0 1 perft 6 = 1440467
short castling gives check:
5k2/8/8/8/8/8/8/4K2R w K - 0 1 perft 6 = 661072
4k2r/8/8/8/8/8/8/5K2 b k - 0 1 perft 6 = 661072
long castling gives check:
3k4/8/8/8/8/8/8/R3K3 w Q - 0 1 perft 6 = 803711
r3k3/8/8/8/8/8/8/3K4 b q - 0 1 perft 6 = 803711
castling (including losing cr due to rook capture):
r3k2r/1b4bq/8/8/8/8/7B/R3K2R w KQkq - 0 1 perft 4 = 1274206
r3k2r/7b/8/8/8/8/1B4BQ/R3K2R b KQkq - 0 1 perft 4 = 1274206
castling prevented:
r3k2r/8/3Q4/8/8/5q2/8/R3K2R b KQkq - 0 1 perft 4 = 1720476
r3k2r/8/5Q2/8/8/3q4/8/R3K2R w KQkq - 0 1 perft 4 = 1720476
promote out of check:
2K2r2/4P3/8/8/8/8/8/3k4 w - - 0 1 perft 6 = 3821001
3K4/8/8/8/8/8/4p3/2k2R2 b - - 0 1 perft 6 = 3821001
discovered check:
8/8/1P2K3/8/2n5/1q6/8/5k2 b - - 0 1 perft 5 = 1004658
5K2/8/1Q6/2N5/8/1p2k3/8/8 w - - 0 1 perft 5 = 1004658
promote to give check:
4k3/1P6/8/8/8/8/K7/8 w - - 0 1 perft 6 = 217342
8/k7/8/8/8/8/1p6/4K3 b - - 0 1 perft 6 = 217342
underpromote to check:
8/P1k5/K7/8/8/8/8/8 w - - 0 1 perft 6 = 92683
8/8/8/8/8/k7/p1K5/8 b - - 0 1 perft 6 = 92683
self stalemate:
K1k5/8/P7/8/8/8/8/8 w - - 0 1 perft 6 = 2217
8/8/8/8/8/p7/8/k1K5 b - - 0 1 perft 6 = 2217
stalemate/checkmate:
8/k1P5/8/1K6/8/8/8/8 w - - 0 1 perft 7 = 567584
8/8/8/8/1k6/8/K1p5/8 b - - 0 1 perft 7 = 567584
double check:
8/8/2k5/5q2/5n2/8/5K2/8 b - - 0 1 perft 4 = 23527
8/5k2/8/5N2/5Q2/2K5/8/8 w - - 0 1 perft 4 = 23527
User avatar
Ajedrecista
Posts: 1966
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: A few positions to test movegen.

Post by Ajedrecista »

Hello Martin:
mar wrote:Here is a list of a few artifical positions to test some of the common pitfalls of move generators.
Each position appears twice with colors reversed.
I think it may be useful to others too.
Of course passing the test doesn't mean the movegen is bug-free.

avoid illegal en passant capture:
8/5bk1/8/2Pp4/8/1K6/8/8 w - d6 0 1 perft 6 = 824064
8/8/1k6/8/2pP4/8/5BK1/8 b - d3 0 1 perft 6 = 824064
en passant capture checks opponent:
8/8/1k6/2b5/2pP4/8/5K2/8 b - d3 0 1 perft 6 = 1440467
8/5k2/8/2Pp4/2B5/1K6/8/8 w - d6 0 1 perft 6 = 1440467
short castling gives check:
5k2/8/8/8/8/8/8/4K2R w K - 0 1 perft 6 = 661072
4k2r/8/8/8/8/8/8/5K2 b k - 0 1 perft 6 = 661072
long castling gives check:
3k4/8/8/8/8/8/8/R3K3 w Q - 0 1 perft 6 = 803711
r3k3/8/8/8/8/8/8/3K4 b q - 0 1 perft 6 = 803711
castling (including losing cr due to rook capture):
r3k2r/1b4bq/8/8/8/8/7B/R3K2R w KQkq - 0 1 perft 4 = 1274206
r3k2r/7b/8/8/8/8/1B4BQ/R3K2R b KQkq - 0 1 perft 4 = 1274206
castling prevented:
r3k2r/8/3Q4/8/8/5q2/8/R3K2R b KQkq - 0 1 perft 4 = 1720476
r3k2r/8/5Q2/8/8/3q4/8/R3K2R w KQkq - 0 1 perft 4 = 1720476
promote out of check:
2K2r2/4P3/8/8/8/8/8/3k4 w - - 0 1 perft 6 = 3821001
3K4/8/8/8/8/8/4p3/2k2R2 b - - 0 1 perft 6 = 3821001
discovered check:
8/8/1P2K3/8/2n5/1q6/8/5k2 b - - 0 1 perft 5 = 1004658
5K2/8/1Q6/2N5/8/1p2k3/8/8 w - - 0 1 perft 5 = 1004658
promote to give check:
4k3/1P6/8/8/8/8/K7/8 w - - 0 1 perft 6 = 217342
8/k7/8/8/8/8/1p6/4K3 b - - 0 1 perft 6 = 217342
underpromote to check:
8/P1k5/K7/8/8/8/8/8 w - - 0 1 perft 6 = 92683
8/8/8/8/8/k7/p1K5/8 b - - 0 1 perft 6 = 92683
self stalemate:
K1k5/8/P7/8/8/8/8/8 w - - 0 1 perft 6 = 2217
8/8/8/8/8/p7/8/k1K5 b - - 0 1 perft 6 = 2217
stalemate/checkmate:
8/k1P5/8/1K6/8/8/8/8 w - - 0 1 perft 7 = 567584
8/8/8/8/1k6/8/K1p5/8 b - - 0 1 perft 7 = 567584
double check:
8/8/2k5/5q2/5n2/8/5K2/8 b - - 0 1 perft 4 = 23527
8/5k2/8/5N2/5Q2/2K5/8/8 w - - 0 1 perft 4 = 23527
Very useful positions! I have tried JetChess 1.0.0.0 and it agrees with all the positions except the two first (avoid illegal en passant capture). Indeed it is a tricky position: JetChess gives Perft(1) = 9 (including cxd6 e.p.) and Perft(6) = 960427, including 136363 of cxd6 e.p.; of course 960427 - 136363 = 824064.

[d]8/5bk1/8/2Pp4/8/1K6/8/8 w - d6 0 1
1 c5-c6 119793
2 c5*d6e 136363
3 Kb3-c3 118973
4 Kb3-a3 82957
5 Kb3-a4 80828
6 Kb3-b4 97074
7 Kb3-a2 76150
8 Kb3-b2 119231
9 Kb3-c2 129058

Total: 960427
[d]8/8/1k6/8/2pP4/8/5BK1/8 b - d3 0 1
1 c4-c3 119793
2 c4*d3e 136363
3 kb6-c6 118973
4 kb6-a6 82957
5 kb6-a5 80828
6 kb6-b5 97074
7 kb6-a7 76150
8 kb6-b7 119231
9 kb6-c7 129058

Total: 960427
In view of that, must I think that JetChess is buggy in some rare/extreme cases? I was able to compute Perft(11) after 1.- f3, f6 (~1.1653e+15) and my result agree with Steven Edward's result. Thanks in advance.

Regards from Spain.

Ajedrecista.
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: A few positions to test movegen.

Post by Steve Maughan »

Also try this one:

[D]3k4/8/8/K1Pp3r/8/8/8/8 w - d6 0 1

Here the white pawn cannot take ep on d6 due to the discovered check. The point being, after both pieces are removed from the board there is discovered check.

Steve
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: A few positions to test movegen.

Post by mar »

Ajedrecista wrote:Hello Martin:

Very useful positions! I have tried JetChess 1.0.0.0 and it agrees with all the positions except the two first (avoid illegal en passant capture). Indeed it is a tricky position: JetChess gives Perft(1) = 9 (including cxd6 e.p.) and Perft(6) = 960427, including 136363 of cxd6 e.p.; of course 960427 - 136363 = 824064.

[d]8/5bk1/8/2Pp4/8/1K6/8/8 w - d6 0 1
1 c5-c6 119793
2 c5*d6e 136363
3 Kb3-c3 118973
4 Kb3-a3 82957
5 Kb3-a4 80828
6 Kb3-b4 97074
7 Kb3-a2 76150
8 Kb3-b2 119231
9 Kb3-c2 129058

Total: 960427
[d]8/8/1k6/8/2pP4/8/5BK1/8 b - d3 0 1
1 c4-c3 119793
2 c4*d3e 136363
3 kb6-c6 118973
4 kb6-a6 82957
5 kb6-a5 80828
6 kb6-b5 97074
7 kb6-a7 76150
8 kb6-b7 119231
9 kb6-c7 129058

Total: 960427
In view of that, must I think that JetChess is buggy in some rare/extreme cases? I was able to compute Perft(11) after 1.- f3, f6 (~1.1653e+15) and my result agree with Steven Edward's result. Thanks in advance.

Regards from Spain.

Ajedrecista.
Hi Jesus,

I'm glad you find it useful.
Yes this is a Jetchess bug for sure. I would be careful using that (perhaps you should contact the author and report a bug?).
Of course, when you calculate from startposition, you probably won't reach such case in first n plies (where n can be large).

Martin
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: A few positions to test movegen.

Post by mar »

Steve Maughan wrote:Also try this one:

[D]3k4/8/8/K1Pp3r/8/8/8/8 w - d6 0 1

Here the white pawn cannot take ep on d6 due to the discovered check. The point being, after both pieces are removed from the board there is discovered check.

Steve
Thanks Steve.
This is actually the same case as the first two testpositions.

Martin
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: A few positions to test movegen.

Post by Steve Maughan »

Hi Marin,

This is removing two pieces, which I believe is the only situation in chess where check is given by removing both pieces.

Steve
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: A few positions to test movegen.

Post by mar »

Steve Maughan wrote:Hi Marin,

This is removing two pieces, which I believe is the only situation in chess where check is given by removing both pieces.

Steve
Hi Steve,
I only see the black pawn removed. Am I missing something?

Martin
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: A few positions to test movegen.

Post by Steve Maughan »

Hi Martin,

To clarify - after c5 x d6 ep there are two pieces removed from the 5th rank, which result in a discovered check (and hence an illegal move). So the white pawn is not removed from the board but is removed from the 5th row.

Steve
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: A few positions to test movegen

Post by elcabesa »

I have found a bug in my UCI setposition command trying your positions :)
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: A few positions to test movegen.

Post by mar »

Steve Maughan wrote:Hi Martin,

To clarify - after c5 x d6 ep there are two pieces removed from the 5th rank, which result in a discovered check (and hence an illegal move). So the white pawn is not removed from the board but is removed from the 5th row.

Steve
Aha I understand now :)
I will add your position to my small suite too then. Thanks.

Martin