Perft position to debug check-evasions via en passant capture

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Perft position to debug check-evasions via en passant capture

Post by R. Tomasi »

I am currently porting the specialized movegenerator for check-evasions from my old engine to Pygmalion. I am aware that lots of test positions that are good for testing move generation are listed on CPW, but there is one special case that maybe isn't covered so well: if the king is in check by a pawn that can be captured en passant. For that purpose I created two test positions and I thought it would be nice to share them here:

[fen]4k3/3p1p2/8/4P3/4K3/8/8/8 b - - 0 1[/fen]
The vanilla move generator of Pygmalion (which is quite well tested) gives these perft results:

Code: Select all

perft 1

  d7d6
  f7f6
  d7d5
  f7f5
  e8e7
  e8d8
  e8f8

depth:  1 nodes:   7.00 N   time:    428 mcs speed:   16.4 kN/s

 Leafs:             7
 Captures:          0
 En passant:        0
 Castles:           0
 Promotions:        0
 Checks:            2
 Checkmates:        0
 Double pushes:     2
 Queenside castles: 0
 Kingside castles:  0

perft 2

  d7d6  : 9
  f7f6  : 9
  d7d5  : 8
  f7f5  : 8
  e8e7  : 8
  e8d8  : 8
  e8f8  : 8

depth:  2 nodes:   14.0 N   time:   2.24 ms  speed:   6.26 kN/s

 Leafs:             58
 Captures:          6
 En passant:        2
 Castles:           0
 Promotions:        0
 Checks:            0
 Checkmates:        0
 Double pushes:     0
 Queenside castles: 0
 Kingside castles:  0

perft 3

  d7d6  : 66
  f7f6  : 66
  d7d5  : 51
  f7f5  : 51
  e8e7  : 64
  e8d8  : 64
  e8f8  : 64

depth:  3 nodes:   72.0 N   time:   2.85 ms  speed:   25.3 kN/s

 Leafs:             426
 Captures:          23
 En passant:        0
 Castles:           0
 Promotions:        0
 Checks:            20
 Checkmates:        0
 Double pushes:     72
 Queenside castles: 0
 Kingside castles:  0

perft 4

  d7d6  : 546
  f7f6  : 546
  d7d5  : 369
  f7f5  : 369
  e8e7  : 511
  e8d8  : 522
  e8f8  : 522

depth:  4 nodes:    498 N   time:   2.70 ms  speed:    184 kN/s

 Leafs:             3385
 Captures:          316
 En passant:        60
 Castles:           0
 Promotions:        0
 Checks:            90
 Checkmates:        0
 Double pushes:     0
 Queenside castles: 0
 Kingside castles:  0

perft 5

  d7d6  : 4076
  f7f6  : 4076
  d7d5  : 2606
  f7f5  : 2606
  e8e7  : 4107
  e8d8  : 4183
  e8f8  : 4183

depth:  5 nodes:   3.88 kN  time:   6.90 ms  speed:    562 kN/s

 Leafs:             25837
 Captures:          1958
 En passant:        0
 Castles:           0
 Promotions:        0
 Checks:            1420
 Checkmates:        0
 Double pushes:     3248
 Queenside castles: 0
 Kingside castles:  0

perft 6

  d7d6  : 33678
  f7f6  : 33678
  d7d5  : 20578
  f7f5  : 20578
  e8e7  : 34232
  e8d8  : 35681
  e8f8  : 35681

depth:  6 nodes:   29.7 kN  time:   39.9 ms  speed:    745 kN/s

 Leafs:             214106
 Captures:          18444
 En passant:        2330
 Castles:           0
 Promotions:        1000
 Checks:            7256
 Checkmates:        0
 Double pushes:     0
 Queenside castles: 0
 Kingside castles:  0
 
[fen]8/8/8/2k5/2p5/8/1P1P4/2K5 w - - 0 1[/fen]
Vanilla movegen yields:

Code: Select all

perft 1

  b2b3
  d2d3
  b2b4
  d2d4
  c1b1
  c1d1
  c1c2

depth:  1 nodes:   7.00 N   time:   1.99 ms  speed:   3.52 kN/s

 Leafs:             7
 Captures:          0
 En passant:        0
 Castles:           0
 Promotions:        0
 Checks:            2
 Checkmates:        0
 Double pushes:     2
 Queenside castles: 0
 Kingside castles:  0

perft 2

  b2b3  : 9
  d2d3  : 9
  b2b4  : 8
  d2d4  : 8
  c1b1  : 8
  c1d1  : 8
  c1c2  : 8

depth:  2 nodes:   14.0 N   time:   2.97 ms  speed:   4.72 kN/s

 Leafs:             58
 Captures:          6
 En passant:        2
 Castles:           0
 Promotions:        0
 Checks:            0
 Checkmates:        0
 Double pushes:     0
 Queenside castles: 0
 Kingside castles:  0

perft 3

  b2b3  : 66
  d2d3  : 66
  b2b4  : 51
  d2d4  : 51
  c1b1  : 64
  c1d1  : 64
  c1c2  : 64

depth:  3 nodes:   72.0 N   time:   2.40 ms  speed:   30.1 kN/s

 Leafs:             426
 Captures:          23
 En passant:        0
 Castles:           0
 Promotions:        0
 Checks:            20
 Checkmates:        0
 Double pushes:     72
 Queenside castles: 0
 Kingside castles:  0

perft 4

  b2b3  : 546
  d2d3  : 546
  b2b4  : 369
  d2d4  : 369
  c1b1  : 522
  c1d1  : 522
  c1c2  : 511

depth:  4 nodes:    498 N   time:   2.57 ms  speed:    194 kN/s

 Leafs:             3385
 Captures:          316
 En passant:        60
 Castles:           0
 Promotions:        0
 Checks:            90
 Checkmates:        0
 Double pushes:     0
 Queenside castles: 0
 Kingside castles:  0

perft 5

  b2b3  : 4076
  d2d3  : 4076
  b2b4  : 2606
  d2d4  : 2606
  c1b1  : 3858
  c1d1  : 4183
  c1c2  : 4107

depth:  5 nodes:   3.88 kN  time:   6.06 ms  speed:    641 kN/s

 Leafs:             25512
 Captures:          1958
 En passant:        0
 Castles:           0
 Promotions:        0
 Checks:            1420
 Checkmates:        0
 Double pushes:     3248
 Queenside castles: 0
 Kingside castles:  0

perft 6

  b2b3  : 32326
  d2d3  : 32174
  b2b4  : 19636
  d2d4  : 19371
  c1b1  : 31474
  c1d1  : 34229
  c1c2  : 32857

depth:  6 nodes:   29.4 kN  time:   38.9 ms  speed:    756 kN/s

 Leafs:             202067
 Captures:          18287
 En passant:        2330
 Castles:           0
 Promotions:        940
 Checks:            7240
 Checkmates:        0
 Double pushes:     0
 Queenside castles: 0
 Kingside castles:  0
 
[Edit: modified first position such that black is on the move]
User avatar
MartinBryant
Posts: 69
Joined: Thu Nov 21, 2013 12:37 am
Location: Manchester, UK
Full name: Martin Bryant

Re: Perft position to debug check-evasions via en passant capture

Post by MartinBryant »

Thank you. I have added them to my collection.
And FWIW my engine agrees with your figures.
User avatar
Ajedrecista
Posts: 1966
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: Perft position to debug check-evasions via en passant capture.

Post by Ajedrecista »

Hello Roland:

I am a bit late in this topic. I confirm your values up to perft(6) in those two positions using JetChess perft counter and I also computed higher perft values of those positions running JetChess and gperft perft counters if someone needs these values for debugging his/her move generator:

Code: Select all

4k3/3p1p2/8/4P3/4K3/8/8/8 b - - 0 1

JetChess 1.0.0.0


perft(7)
  1   d7-d6      259530
  2   d7-d5      151764
  3   f7-f6      259530
  4   f7-f5      151764
  5  ke8-f8      283520
  6  ke8-d8      291055
  7  ke8-e7      272088
Total:          1669251


perft(8)
  1   d7-d6     2074539
  2   d7-d5     1171563
  3   f7-f6     2078927
  4   f7-f5     1179230
  5  ke8-f8     2349104
  6  ke8-d8     2415999
  7  ke8-e7     2213591
Total:         13482953


perft(9)
  1   d7-d6    16196771
  2   d7-d5     8841533
  3   f7-f6    16140718
  4   f7-f5     8851088
  5  ke8-f8    18409361
  6  ke8-d8    19951202
  7  ke8-e7    17698749
Total:        106089422


perft(10)
  1   d7-d6   127258381
  2   d7-d5    67837378
  3   f7-f6   127064750
  4   f7-f5    68457038
  5  ke8-f8   151663287
  6  ke8-d8   165543203
  7  ke8-e7   143078506
Total:        850902543


perft(11)
  1   d7-d6   998464161
  2   d7-d5   518340110
  3   f7-f6   985921628
  4   f7-f5   517606315
  5  ke8-f8  1173459894
  6  ke8-d8  1358646295
  7  ke8-e7  1144615372
Total:       6697053775


perft(12)
  1   d7-d6   7877659338
  2   d7-d5   4037196876
  3   f7-f6   7784946694
  4   f7-f5   4060541941
  5  ke8-f8   9868190412
  6  ke8-d8  11597366530
  7  ke8-e7   9484291615
Total:       54710193406


perft(13)
  1   d7-d6  61555989933
  2   d7-d5  30955427544
  3   f7-f6  60011634514
  4   f7-f5  30756351754
  5  ke8-f8  75397193248
  6  ke8-d8  93503479452
  7  ke8-e7  75039604285
Total:      427219680730


perft(14)
  1   d7-d6  504319653159
  2   d7-d5  254042954085
  3   f7-f6  491445008702
  4   f7-f5  253281441310
  5  ke8-f8  676477843221
  6  ke8-d8  861706532147
  7  ke8-e7  668866920904
Total:      3710140353528


perft(15)
  1   d7-d6  3888388078053
  2   d7-d5  1944317083247
  3   f7-f6  3736902501177
  4   f7-f5  1917834661361
  5  ke8-f8  5061992521346
  6  ke8-d8  6750142286220
  7  ke8-e7  5167851513828
Total:      28467428645232


perft(16)
  1   d7-d6  34941880168076
  2   d7-d5  17816259771536
  3   f7-f6  33532206051655
  4   f7-f5  17507795644360
  5  ke8-f8  51611810812478
  6  ke8-d8  71572996638515
  7  ke8-e7  53043795424381
Total:      280026744511001


perft(17)
  1   d7-d6  262486651389299
  2   d7-d5  135428898412814
  3   f7-f6  248738389558472
  4   f7-f5  132395674119964
  5  ke8-f8  374341736447885
  6  ke8-d8  538241247102648
  7  ke8-e7  394924537986204
Total:      2086557135017286

************

4k3/3p1p2/8/4P3/4K3/8/8/8 b - - 0 1

gperft 1.1

perft(18)
d6         2,772,154,657,643,006
f6         2,625,273,976,529,558
d5+        1,476,532,580,812,573
f5+        1,426,087,209,745,893
Kd8        6,916,413,542,837,065
Kf8        4,611,053,385,705,306
Ke7        4,952,033,304,959,548
TOTAL     24,779,548,658,232,949


perft(19)
d6         20,064,099,873,050,071
f6         18,804,824,365,328,789
d5+        11,203,293,004,277,077
f5+        10,864,903,283,178,065
Ke7        35,326,863,300,692,230
Kd8        49,754,830,872,794,509
Kf8        32,279,125,643,203,243
TOTAL     178,297,940,342,523,984


perft(20)
d6         262,025,967,157,079,357
f6         246,107,223,347,805,971
d5+        149,645,240,404,676,931
f5+        142,649,981,635,181,689
Kd8        778,419,144,680,955,803
Kf8        489,260,338,664,764,038
Ke7        546,003,163,145,901,675
TOTAL    2,614,111,059,036,365,464

Code: Select all

8/8/8/2k5/2p5/8/1P1P4/2K5 w - - 0 1

JetChess 1.0.0.0


perft(7)
  1   b2-b3      240667
  2   b2-b4      139689
  3   d2-d3      242999
  4   d2-d4      139862
  5  Kc1-d1      278573
  6  Kc1-b1      222936
  7  Kc1-c2      257000
Total:          1521726


perft(8)
  1   b2-b3     1860648
  2   b2-b4     1050556
  3   d2-d3     1872393
  4   d2-d4     1032835
  5  Kc1-d1     2235215
  6  Kc1-b1     1764133
  7  Kc1-c2     2013842
Total:         11829622


perft(9)
  1   b2-b3    13713976
  2   b2-b4     7465643
  3   d2-d3    14177985
  4   d2-d4     7532922
  5  Kc1-d1    18495711
  6  Kc1-b1    12436918
  7  Kc1-c2    15550320
Total:         89373475


perft(10)
  1   b2-b3   105393400
  2   b2-b4    56811379
  3   d2-d3   108751512
  4   d2-d4    56101963
  5  Kc1-d1   150686215
  6  Kc1-b1    98371169
  7  Kc1-c2   122547750
Total:        698663388


perft(11)
  1   b2-b3   779084344
  2   b2-b4   408923058
  3   d2-d3   833473339
  4   d2-d4   417750027
  5  Kc1-d1  1250663880
  6  Kc1-b1   698819405
  7  Kc1-c2   943567500
Total:       5332281553


perft(12)
  1   b2-b3   6051475048
  2   b2-b4   3181421145
  3   d2-d3   6475311566
  4   d2-d4   3193351213
  5  Kc1-d1  10641028983
  6  Kc1-b1   5618746784
  7  Kc1-c2   7670371723
Total:       42831706462


perft(13)
  1   b2-b3  44903265810
  2   b2-b4  23205504815
  3   d2-d3  50024420339
  4   d2-d4  24126299102
  5  Kc1-d1  87332495770
  6  Kc1-b1  40205671365
  7  Kc1-c2  58988150173
Total:      328785807374


perft(14)
  1   b2-b3  363677593047
  2   b2-b4  189878455892
  3   d2-d3  405913166799
  4   d2-d4  196387791637
  5  Kc1-d1  814798677354
  6  Kc1-b1  340149205538
  7  Kc1-c2  518465830852
Total:      2829270721119


perft(15)
  1   b2-b3  2697186575710
  2   b2-b4  1408420791872
  3   d2-d3  3130943179402
  4   d2-d4  1495861599679
  5  Kc1-d1  6514602366091
  6  Kc1-b1  2443961503034
  7  Kc1-c2  3950307198365
Total:      21641283214153


perft(16)
  1   b2-b3  24067565963937
  2   b2-b4  12736710808886
  3   d2-d3  27953633114870
  4   d2-d4  13760062868919
  5  Kc1-d1  70814374692015
  6  Kc1-b1  23034191034701
  7  Kc1-c2  40184971979701
Total:      212551510463029


perft(17)
  1   b2-b3  176519554644901
  2   b2-b4   96323358179107
  3   d2-d3  212155842671718
  4   d2-d4  104683306182729
  5  Kc1-d1  543247847196143
  6  Kc1-b1  164412422569685
  7  Kc1-c2  298939898947818
Total:      1596282230392101

************

8/8/8/2k5/2p5/8/1P1P4/2K5 w - - 0 1

gperft 1.1


perft(18)
b3         1,865,205,851,715,333
d3         2,227,575,785,169,709
b4+        1,021,101,896,087,835
Kb1        1,847,733,918,328,284
d4+        1,157,855,993,291,257
Kd1        7,173,440,269,153,839
Kc2        3,729,998,900,673,475
TOTAL     19,022,912,614,419,732


perft(19)
b3         13,355,790,947,624,058
d3         16,386,763,373,373,161
b4+         7,936,743,773,237,255
d4+         8,783,384,191,671,073
Kb1        12,969,878,499,295,475
Kc2        26,801,191,696,849,773
Kd1        52,480,180,851,448,791
TOTAL     138,713,933,333,499,586


perft(20)
b3         175,658,706,753,608,778
d3         212,071,277,613,985,758
b4+        101,671,719,709,631,478
Kb1        180,483,671,713,379,560
d4+        119,310,791,237,441,289
Kd1        836,016,553,542,298,564
Kc2        412,145,242,908,063,359
TOTAL    2,037,357,963,478,408,786
Higher values of perft could be calculated, but 64-bit integer overflows would happen. They can be corrected using Montecarlo perft estimates to know the number of overflows, but perft(20) is enough.

Summary of perft values of the positions without divide:

Code: Select all

4k3/3p1p2/8/4P3/4K3/8/8/8 b - - 0 1

perft( 1) =                         7
perft( 2) =                        58
perft( 3) =                       426
perft( 4) =                     3,385
perft( 5) =                    25,837
perft( 6) =                   214,106
perft( 7) =                 1,669,251
perft( 8) =                13,482,953
perft( 9) =               106,089,422
perft(10) =               850,902,543
perft(11) =             6,697,053,775
perft(12) =            54,710,193,406
perft(13) =           427,219,680,730
perft(14) =         3,710,140,353,528
perft(15) =        28,467,428,645,232
perft(16) =       280,026,744,511,001
perft(17) =     2,086,557,135,017,286
perft(18) =    24,779,548,658,232,949
perft(19) =   178,297,940,342,523,984
perft(20) = 2,614,111,059,036,365,464

Code: Select all

8/8/8/2k5/2p5/8/1P1P4/2K5 w - - 0 1

perft( 1) =                         7
perft( 2) =                        58
perft( 3) =                       426
perft( 4) =                     3,385
perft( 5) =                    25,512
perft( 6) =                   202,067
perft( 7) =                 1,521,726
perft( 8) =                11,829,622
perft( 9) =                89,373,475
perft(10) =               698,663,388
perft(11) =             5,332,281,553
perft(12) =            42,831,706,462
perft(13) =           328,785,807,374
perft(14) =         2,829,270,721,119
perft(15) =        21,641,283,214,153
perft(16) =       212,551,510,463,029
perft(17) =     1,596,282,230,392,101
perft(18) =    19,022,912,614,419,732
perft(19) =   138,713,933,333,499,586
perft(20) = 2,037,357,963,478,408,786
I hope no typos.

Regards from Spain.

Ajedrecista.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Perft position to debug check-evasions via en passant capture.

Post by R. Tomasi »

Ajedrecista wrote: Sat Sep 18, 2021 8:51 pm ...
Thank you! Just out of curiosity: how long did it take to calculate these values?
User avatar
Ajedrecista
Posts: 1966
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: Perft position to debug check-evasions via en passant capture.

Post by Ajedrecista »

Hello Roland:
R. Tomasi wrote: Sat Sep 18, 2021 10:53 pmThank you! Just out of curiosity: how long did it take to calculate these values?
It took few time because JetChess and gperft are not common chess engines but highly optimised perft counters that have hash tables, bulk counting and other tricks to compute perft values insanely fast. Answering to your question: perft(17) in less than two minutes with JetChess (single core) and perft(20) in around four minutes with gperft (4 threads and 2 GB of hash), which is faster than JetChess.

------------

JetChess is single core, 32-bit GUI and its hash table in perft is up to 1 GB. It could be downloaded from archive.org backups that can be found in the following post and URLs:

Re: Maximum number of pseudo legal moves.

https://web.archive.org/web/20171119065 ... e/jetchess

https://web.archive.org/web/20150402020 ... .0.0.0.zip

But for some reason I can not access to these backups today, it looks like the WayBack Machine is down or I have problems with the WayBack Machine. You might be luckier today or in the future with those links. Anyway, I have a copy that can be uploaded anytime. By the way, the ZIP can be downloaded if you right click on the URL finishing with .zip and click 'Save link as...'.

------------

gperft is multi-threaded, 64-bit CLI, making it faster than JetChess. You must start gperft from the command prompt (pointing to the path where gperft is saved). Some versions can be downloaded from the URL of the next post:

Re: Magic bitboard perft.

gperft.7z (1.03 MB)

There is a faster version (1.2d) which I did not download in its day and is not downloadable anymore, but gperft 1.1 should be fast enough for your needs.

------------

Both perft counters are easy to use if you follow the help/readme.

Regards from Spain.

Ajedrecista.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Perft position to debug check-evasions via en passant capture.

Post by R. Tomasi »

Ajedrecista wrote: Sun Sep 19, 2021 1:24 pm Hello Roland:
R. Tomasi wrote: Sat Sep 18, 2021 10:53 pmThank you! Just out of curiosity: how long did it take to calculate these values?
It took few time because JetChess and gperft are not common chess engines but highly optimised perft counters that have hash tables, bulk counting and other tricks to compute perft values insanely fast. Answering to your question: perft(17) in less than two minutes with JetChess (single core) and perft(20) in around four minutes with gperft (4 threads and 2 GB of hash), which is faster than JetChess.
That indeed is insanely fast - even for specialized perft counters. Thank you for posting all the links. I will definitely have a look :)