REPORT: wrong perft result by qperft.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Ajedrecista
Posts: 1969
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

REPORT: wrong perft result by qperft.

Post by Ajedrecista »

Hello:

Sorry for this extremely long post.

[d]rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6

I was testing this position for see if JetChess 1.0.0.0 and/or qperft (by Muller, but this time compiled my myself with mingw32) had problems with O-O for white: there is no problem here until Perft(6), (both results match). But I found one flaw in (at least) one of these two perft counters at Perft(7) (256 MB of hash for each perft counter):

Code: Select all

qperft 7 "H24" "rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6"
Hash-table size = ffffff, Starts at 4f0040,section = 1fffff
 - - - - - - - - - - - -
 - - - - - - - - - - - -
 - - r n b q k b . r - -
 - - p p . p . p p p - -
 - - . . p . . . . . - -
 - - . . . . P . . . - -
 - - . . B . . . . . - -
 - - . . . . . . . . - -
 - - P P P . N n P P - -
 - - R N B Q K . . R - -
 - - - - - - - - - - - -
 - - - - - - - - - - - -

Quick Perft by H.G. Muller
Perft mode: Hash-table size = 256MB, bulk counting in horizon nodes

perft( 1)=           42 ( 0.000 sec)
perft( 2)=         1352 ( 0.000 sec)
perft( 3)=        53392 ( 0.000 sec)
perft( 4)=      1761505 ( 0.031 sec)
perft( 5)=     70202861 ( 0.735 sec)
perft( 6)=   2362704901 (13.078 sec)
perft( 7)=  94855003088 (358.000 sec)

Code: Select all

rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6

  1  Qd1-d2  2481769422
  2  Qd1-d3  3719739001
  3  Qd1-d4  3598056747
  4  Qd1-d5  2815305249
  5  Qd1-d6  2314600161
  6  Qd1*d7   207937563
  7  Rh1-g1  1983977646
  8  Rh1-f1  2220729699
  9  Bc1-d2  2107363662
 10  Bc1-e3  3184524390
 11  Bc1-f4  2482656228
 12  Bc1-g5  2400385594
 13  Bc1-h6  2344263758
 14  Bc4-b5  2130713616
 15  Bc4-a6  1855061374
 16  Bc4-d5  2046941872
 17  Bc4-e6  2444185312
 18  Bc4*f7    86568355
 19  Bc4-d3  1886965922
 20  Bc4-b3  1816240296
 21  Nb1-a3  2002068159
 22  Nb1-c3  2655487727
 23  Nb1-d2  1435627351
 24  Ne2-c3  3057530890
 25  Ne2-d4  3061284388
 26  Ne2-f4  2949871106
 27  Ne2-g3  2865273204
 28  Ne2-g1  2354927176
 29   a2-a3  2245837704
 30   a2-a4  2548648372
 31   b2-b3  2166557328
 32   b2-b4  2263311424
 33   c2-c3  2411002727
 34   g2-g3  1981011243
 35   g2-g4  2033046400
 36   h2-h3  2217212927
 37   h2-h4  2387827889
 38   e5-e6  2461806026
 39     0-0  2291266832
 40  Ke1-f1  2483161986
 41  Ke1-d2  1152858513
 42  Ke1*f2  1701268892

Total:      94854874131

94,854,874,131 (move pathes after 7 half moves).

Time: 380.995 s (0:06:20.995).
Splitting the results in qperft:

Code: Select all

2. e1g1 moves = 2291266832 (10.625 sec)
2. h2h3 moves = 2217212927 (13.391 sec)
2. h2h4 moves = 2387827889 (14.125 sec)
2. g2g3 moves = 1981011243 (11.062 sec)
2. g2g4 moves = 2033046400 (11.328 sec)
2. c2c3 moves = 2411002727 (11.422 sec)
2. b2b3 moves = 2166557328 (10.844 sec)
2. b2b4 moves = 2263311424 (11.141 sec)
2. a2a3 moves = 2245837704 (10.765 sec)
2. a2a4 moves = 2548648372 (11.703 sec)
2. e5e6 moves = 2461934981 (11.125 sec)
2. b1a3 moves = 2002068159 (10.047 sec)
2. b1c3 moves = 2655487727 (10.250 sec)
2. b1d2 moves = 1435627351 ( 5.594 sec)
2. e2c3 moves = 3057530890 (13.375 sec)
2. e2d4 moves = 3061284388 (12.719 sec)
2. e2f4 moves = 2949871106 (13.500 sec)
2. e2g3 moves = 2865273204 (12.797 sec)
2. e2g1 moves = 2354927176 (11.562 sec)
2. c4b5 moves = 2130713616 ( 9.625 sec)
2. c4a6 moves = 1855061374 ( 7.344 sec)
2. c4d3 moves = 1886965922 ( 6.500 sec)
2. c4d5 moves = 2046941872 ( 7.484 sec)
2. c4e6 moves = 2444185312 (11.188 sec)
2. c4f7 moves =   86568355 ( 0.922 sec)
2. c4b3 moves = 1816240298 ( 7.156 sec)
2. c1d2 moves = 2107363662 ( 6.969 sec)
2. c1e3 moves = 3184524390 (12.718 sec)
2. c1f4 moves = 2482656228 ( 8.297 sec)
2. c1g5 moves = 2400385594 (10.422 sec)
2. c1h6 moves = 2344263758 (10.469 sec)
2. d1d2 moves = 2481769422 ( 9.844 sec)
2. d1d3 moves = 3719739001 (11.843 sec)
2. d1d4 moves = 3598056747 (11.719 sec)
2. d1d5 moves = 2815305249 ( 8.469 sec)
2. d1d6 moves = 2314600161 ( 7.484 sec)
2. d1d7 moves =  207937563 ( 2.891 sec)
2. h1g1 moves = 1983977646 ( 3.609 sec)
2. h1f1 moves = 2220729699 ( 4.172 sec)
2. e1f1 moves = 2483161986 ( 3.469 sec)
2. e1f2 moves = 1701268892 ( 5.578 sec)
2. e1d2 moves = 1152858513 ( 4.688 sec)

perft( 7)=  94855003088 (390.235 sec)
JetChess and qperft do not agree (128,957 nodes more in qperft):

Code: Select all

[Nodes(qperft)] - [nodes(JetChess)] =

= 128,955 (e6)
=       2 (Bb3)
The comparison was made by eye.... I hope no errors.

Only change in qperft source was replacing %10lld by %10I64d and %12lld by %12I64d. Reasons for these changes:

http://talkchess.com/forum/viewtopic.ph ... 10&t=40108

http://talkchess.com/forum/viewtopic.ph ... 12&t=40108

I did some dirty job, searching for the errors:

Code: Select all

(JetChess 1.0.0.0): e6 played (128 MB of hash).

rnbqkb1r/pp1p1ppp/2p1P3/8/2B5/8/PPP1NnPP/RNBQK2R b KQkq - 0 6

  1  qd8-c7    80381152
  2  qd8-b6    78384048
  3  qd8-a5    21945709
  4  qd8-e7    62217713
  5  qd8-f6    91231153
  6  qd8-g5   105270469
  7  qd8-h4    83720856
  8  rh8-g8    74139349
  9  bf8-e7    75419103
 10  bf8-d6    96107199
 11  bf8-c5    88600632
 12  bf8-b4    15650634
 13  bf8-a3    83712650
 14  nf2*d1    42513258
 15  nf2*h1    46660634
 16  nf2-d3     7357733
 17  nf2-e4    75283737
 18  nf2-g4    67607241
 19  nf2-h3    56792704
 20  nb8-a6    82211968
 21   c6-c5    65250953
 22   a7-a6    70418560
 23   a7-a5    77371240
 24   b7-b6    72566559
 25   b7-b5    76728327
 26   d7-d6    67036802
 27   d7-d5    82257295
 28   d7*e6    86701509
 29   f7-f6    54438728
 30   f7-f5    64186383
 31   f7*e6    64535721
 32   g7-g6    78034448
 33   g7-g5    66169827
 34   h7-h6    74322298
 35   h7-h5    78705132
 36  ke8-e7    47874302

Total:       2461806026

2,461,806,026 (move pathes after 6 half moves).

Time: 11.574 s (0:00:11.574).

Code: Select all

qperft 6 "H23" "-2" "rnbqkb1r/pp1p1ppp/2p1P3/8/2B5/8/PPP1NnPP/RNBQK2R b KQkq - 0 6"
Hash-table size = 7fffff, Starts at 4f0040,section = fffff
 - - - - - - - - - - - -
 - - - - - - - - - - - -
 - - r n b q k b . r - -
 - - p p . p . p p p - -
 - - . . p . P . . . - -
 - - . . . . . . . . - -
 - - . . B . . . . . - -
 - - . . . . . . . . - -
 - - P P P . N n P P - -
 - - R N B Q K . . R - -
 - - - - - - - - - - - -
 - - - - - - - - - - - -

Quick Perft by H.G. Muller
Perft mode: Hash-table size = 128MB, bulk counting in horizon nodes

2. c6c5 moves =   65256159 ( 0.610 sec)
2. h7h6 moves =   74327157 ( 0.718 sec)
2. h7h5 moves =   78710388 ( 0.750 sec)
2. g7g6 moves =   78039114 ( 0.703 sec)
2. g7g5 moves =   66173473 ( 0.610 sec)
2. f7e6 moves =   64535721 ( 0.547 sec)
2. f7f6 moves =   54441466 ( 0.468 sec)
2. f7f5 moves =   64191163 ( 0.547 sec)
2. d7e6 moves =   86701509 ( 0.735 sec)
2. d7d6 moves =   67046267 ( 0.515 sec)
2. d7d5 moves =   82266683 ( 0.672 sec)
2. b7b6 moves =   72570447 ( 0.500 sec)
2. b7b5 moves =   76734004 ( 0.563 sec)
2. a7a6 moves =   70423024 ( 0.453 sec)
2. a7a5 moves =   77376491 ( 0.500 sec)
2. f2d3 moves =    7357733 ( 0.078 sec)
2. f2e4 moves =   75289295 ( 0.469 sec)
2. f2g4 moves =   67612137 ( 0.375 sec)
2. f2h3 moves =   56797036 ( 0.297 sec)
2. f2h1 moves =   46664359 ( 0.265 sec)
2. f2d1 moves =   42517678 ( 0.297 sec)
2. b8a6 moves =   82217426 ( 0.422 sec)
2. d8e7 moves =   62217717 ( 0.281 sec)
2. d8f6 moves =   91234424 ( 0.453 sec)
2. d8g5 moves =  105274408 ( 0.469 sec)
2. d8h4 moves =   83723867 ( 0.406 sec)
2. d8c7 moves =   80384080 ( 0.250 sec)
2. d8b6 moves =   78387062 ( 0.344 sec)
2. d8a5 moves =   21945709 ( 0.109 sec)
2. f8e7 moves =   75419070 ( 0.344 sec)
2. f8d6 moves =   96110664 ( 0.406 sec)
2. f8c5 moves =   88603987 ( 0.344 sec)
2. f8b4 moves =   15650634 ( 0.094 sec)
2. f8a3 moves =   83715833 ( 0.328 sec)
2. h8g8 moves =   74144265 ( 0.109 sec)
2. e8e7 moves =   47874382 ( 0.094 sec)
perft( 6)=   2461934832 (15.125 sec)

Code: Select all

All this math was done by hand, so may contain errors:

[Nodes(qperft)] - [nodes(JetChess)] = 128,806

c5:   5,206
h6:   4,859
h5:   5,256
g6:   4,666
g5:   3,646
fxe6:     0
f6:   2,738
f5:   4,780
dxe6:     0
d6:   9,465
d5:   9,388
b6:   3,888
b5:   5,677
a6:   4,464
a5:   5,251
Nd3:      0
Ne4:  5,558
Ng4:  4,896
Nh3:  4,332
Nxh1: 3,725
Nxd1: 4,420
Na6:  5,458
Qe7:      4
Qf6:  3,271
Qg5:  3,939
Qh4:  3,011
Qc7:  2,928
Qb6:  3,044
Qa5:      0
Be7:    -33
Bd6:  3,465
Bc5:  3,355
Bb4+:     0
Ba3:  3,183
Rg8:  4,916
Ke7:     80
--------------------------------------------------

Code: Select all

(JetChess 1.0.0.0): Bb3 played (128 MB of hash).

rnbqkb1r/pp1p1ppp/2p5/4P3/8/1B6/PPP1NnPP/RNBQK2R b KQkq - 1 6

  1  qd8-c7    54525077
  2  qd8-b6    58096159
  3  qd8-a5    13505005
  4  qd8-e7    53302902
  5  qd8-f6    70060805
  6  qd8-g5    73090912
  7  qd8-h4    67702711
  8  rh8-g8    57085208
  9  bf8-e7    60529998
 10  bf8-d6    68409266
 11  bf8-c5    68305577
 12  bf8-b4    12613053
 13  bf8-a3    65315697
 14  nf2*d1    31840592
 15  nf2*h1    35327507
 16  nf2-d3     5037855
 17  nf2-e4    58142514
 18  nf2-g4    51764063
 19  nf2-h3    43315381
 20  nb8-a6    63977245
 21   c6-c5    52391837
 22   a7-a6    53685043
 23   a7-a5    59377653
 24   b7-b6    56117504
 25   b7-b5    60985564
 26   d7-d6    74907507
 27   d7-d5    73250093
 28   f7-f6    53848827
 29   f7-f5    57438047
 30   g7-g6    60001019
 31   g7-g5    50604958
 32   h7-h6    57272220
 33   h7-h5    60840404
 34  ke8-e7    33572093

Total:       1816240296

1,816,240,296 (move pathes after 6 half moves).

Time: 9.490 s (0:00:09.490).

Code: Select all

qperft 6 "H23" "-2" "rnbqkb1r/pp1p1ppp/2p5/4P3/8/1B6/PPP1NnPP/RNBQK2R b KQkq - 1 6"
Hash-table size = 7fffff, Starts at 4f0040,section = fffff
 - - - - - - - - - - - -
 - - - - - - - - - - - -
 - - r n b q k b . r - -
 - - p p . p . p p p - -
 - - . . p . . . . . - -
 - - . . . . P . . . - -
 - - . . . . . . . . - -
 - - . B . . . . . . - -
 - - P P P . N n P P - -
 - - R N B Q K . . R - -
 - - - - - - - - - - - -
 - - - - - - - - - - - -

Quick Perft by H.G. Muller
Perft mode: Hash-table size = 128MB, bulk counting in horizon nodes

2. c6c5 moves =   52391837 ( 0.516 sec)
2. h7h6 moves =   57272220 ( 0.578 sec)
2. h7h5 moves =   60840404 ( 0.594 sec)
2. g7g6 moves =   60001019 ( 0.578 sec)
2. g7g5 moves =   50604958 ( 0.484 sec)
2. f7f6 moves =   53848827 ( 0.454 sec)
2. f7f5 moves =   57438047 ( 0.500 sec)
2. d7d6 moves =   74907507 ( 0.593 sec)
2. d7d5 moves =   73250093 ( 0.625 sec)
2. b7b6 moves =   56117504 ( 0.422 sec)
2. b7b5 moves =   60985564 ( 0.453 sec)
2. a7a6 moves =   53685043 ( 0.375 sec)
2. a7a5 moves =   59377653 ( 0.407 sec)
2. f2d3 moves =    5037855 ( 0.062 sec)
2. f2e4 moves =   58142514 ( 0.375 sec)
2. f2g4 moves =   51764063 ( 0.313 sec)
2. f2h3 moves =   43315381 ( 0.250 sec)
2. f2h1 moves =   35327507 ( 0.218 sec)
2. f2d1 moves =   31840592 ( 0.235 sec)
2. b8a6 moves =   63977245 ( 0.359 sec)
2. d8e7 moves =   53302902 ( 0.266 sec)
2. d8f6 moves =   70060805 ( 0.297 sec)
2. d8g5 moves =   73090912 ( 0.343 sec)
2. d8h4 moves =   67702711 ( 0.360 sec)
2. d8c7 moves =   54525077 ( 0.203 sec)
2. d8b6 moves =   58096159 ( 0.281 sec)
2. d8a5 moves =   13505005 ( 0.078 sec)
2. f8e7 moves =   60529998 ( 0.266 sec)
2. f8d6 moves =   68409266 ( 0.234 sec)
2. f8c5 moves =   68305577 ( 0.266 sec)
2. f8b4 moves =   12613053 ( 0.078 sec)
2. f8a3 moves =   65315697 ( 0.234 sec)
2. h8g8 moves =   57085208 ( 0.078 sec)
2. e8e7 moves =   33572093 ( 0.063 sec)
perft( 6)=   1816240296 (11.438 sec)
--------------------------------------------------

Divided Perft(7) of Bb3 is wrong by only 2 nodes, but when doing Perft(6) of Bb3 the result is good (some hidden bug?). More complicated seems to me the other case (e6). I run perft of Critter 1.4 and Stockfish 2.2.2 (both of them in console mode) in the following position:

[d]rnbqkb1r/pp1p1ppp/2p1P3/8/2B5/8/PPP1NnPP/RNBQK2R b - 0 6

Code: Select all

Critter v1.4 32-bit, by Richard Vida
position fen rnbqkb1r/pp1p1ppp/2p1P3/8/2B5/8/PPP1NnPP/RNBQK2R b KQkq - 0 6
perft 6
2461806026 nodes in 87000 ms, 28296 knps

Code: Select all

Stockfish 2.2.2 JA by Tord Romstad, Marco Costalba and Joona Kiiski
position fen rnbqkb1r/pp1p1ppp/2p1P3/8/2B5/8/PPP1NnPP/RNBQK2R b KQkq - 0 6
perft 6

Nodes 2461806026
Time (ms) 59953
Nodes/second 41062265
I wonder the results of GNU 5.07.173b, NebiyuChess 1.42, etc. (too slow in my computer). I encourage other people to check this position with their own move generators, just for verification purposes.

Then, I tried dedicated perft programmes:

Code: Select all

OliPerft -7 "rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6"
 r n b q k b . r
 p p . p . p p p
 . . p . . . . .
 . . . . P . . .
 . . B . . . . .
 . . . . . . . .
 P P P . N n P P
 R N B Q K . . R

Ke1xf2: 1701268892
Ke1-f1: 2483161986
Ke1-d2: 1152858513
Pa2-a3: 2245837704
Pa2-a4: 2548648372
Pb2-b3: 2166557328
Pb2-b4: 2263311424
Pc2-c3: 2411002727
Pg2-g3: 1981011243
Pg2-g4: 2033046400
Ph2-h3: 2217212927
Ph2-h4: 2387827889
Pe5-e6: 2461806026
Nb1-d2: 1435627351
Nb1-a3: 2002068159
Nb1-c3: 2655487727
Ne2-g1: 2354927176
Ne2-c3: 3057530890
Ne2-g3: 2865273204
Ne2-d4: 3061284388
Ne2-f4: 2949871106
Rh1-f1: 2220729699
Rh1-g1: 1983977646
Ke1-g1: 2291266832
Bc1-d2: 2107363662
Bc1-e3: 3184524390
Bc1-f4: 2482656228
Bc1-g5: 2400385594
Bc1-h6: 2344263758
Bc4xf7: 86568355
Bc4-b3: 1816240296
Bc4-d3: 1886965922
Bc4-b5: 2130713616
Bc4-d5: 2046941872
Bc4-a6: 1855061374
Bc4-e6: 2444185312
Qd1xd7: 207937563
Qd1-d2: 2481769422
Qd1-d3: 3719739001
Qd1-d4: 3598056747
Qd1-d5: 2815305249
Qd1-d6: 2314600161

Nodes: 94854874131 cs: 126339 knps: 75079

Code: Select all

frcperft-win32

frcperft 1.0, (C) 2008-2011 AJ Siemelink
single threaded, no hashing, mode=FAST, extract=BSF32, count=LOOP

   +---+---+---+---+---+---+---+---+
 8 |*r*|*n*|*b*|*q*|*k*|*b*|*n*|*r*|
   +---+---+---+---+---+---+---+---+
 7 |*p*|*p*|*p*|*p*|*p*|*p*|*p*|*p*|
   +---+---+---+---+---+---+---+---+
 6 |   |   |   |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 5 |   |   |   |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 4 |   |   |   |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 3 |   |   |   |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 2 |(P)|(P)|(P)|(P)|(P)|(P)|(P)|(P)|
   +---+---+---+---+---+---+---+---+
 1 |(R)|(N)|(B)|(Q)|(K)|(B)|(N)|(R)|
   +---+---+---+---+---+---+---+---+
     a   b   c   d   e   f   g   h

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
interactive mode, type 'help'+Enter for help
% fen rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6

   +---+---+---+---+---+---+---+---+
 8 |*r*|*n*|*b*|*q*|*k*|*b*|   |*r*|
   +---+---+---+---+---+---+---+---+
 7 |*p*|*p*|   |*p*|   |*p*|*p*|*p*|
   +---+---+---+---+---+---+---+---+
 6 |   |   |*p*|   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 5 |   |   |   |   |(P)|   |   |   |
   +---+---+---+---+---+---+---+---+
 4 |   |   |(B)|   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 3 |   |   |   |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 2 |(P)|(P)|(P)|   |(N)|*n*|(P)|(P)|
   +---+---+---+---+---+---+---+---+
 1 |(R)|(N)|(B)|(Q)|(K)|   |   |(R)|
   +---+---+---+---+---+---+---+---+
     a   b   c   d   e   f   g   h

rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 1
% divide 7
O-O      2291266832
a4       2548648372
b4       2263311424
g4       2033046400
h4       2387827889
a3       2245837704
b3       2166557328
c3       2411002727
g3       1981011243
h3       2217212927
e6       2461806026
Nd2      1435627351
Na3      2002068159
Nbc3     2655487727
Ng1      2354927176
Nec3     3057530890
Ng3      2865273204
Nd4      3061284388
Nf4      2949871106
Bd2      2107363662
Be3      3184524390
Bf4      2482656228
Bg5      2400385594
Bh6      2344263758
Bb3      1816240296
Bd3      1886965922
Bb5      2130713616
Bd5      2046941872
Ba6      1855061374
Be6      2444185312
Bxf7       86568355
Qd2      2481769422
Qd3      3719739001
Qd4      3598056747
Qd5      2815305249
Qd6      2314600161
Qxd7      207937563
Rf1      2220729699
Rg1      1983977646
Kf1      2483161986
Kd2      1152858513
Kxf2     1701268892
-------------------
total    94854874131
% Around 72 minutes!

Code: Select all

i-perft -divide 7 "rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6"

i-perft 1.0 (c) 2006-2008 AJ Siemelink


   +---+---+---+---+---+---+---+---+
 8 |*r*|*n*|*b*|*q*|*k*|*b*|   |*r*|
   +---+---+---+---+---+---+---+---+
 7 |*p*|*p*|   |*p*|   |*p*|*p*|*p*|
   +---+---+---+---+---+---+---+---+
 6 |   |   |*p*|   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 5 |   |   |   |   |(P)|   |   |   |
   +---+---+---+---+---+---+---+---+
 4 |   |   |(B)|   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 3 |   |   |   |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
 2 |(P)|(P)|(P)|   |(N)|*n*|(P)|(P)|
   +---+---+---+---+---+---+---+---+
 1 |(R)|(N)|(B)|(Q)|(K)|   |   |(R)|
   +---+---+---+---+---+---+---+---+
     a   b   c   d   e   f   g   h

--divide--------------
Ke1g1      2291266832
e5e6       2325676972
a2a3       2123107962
a2a4       2413850557
b2b3       2046782855
b2b4       2141251457
c2c3       2279251420
g2g3       1868008811
g2g4       1917481468
h2h3       2098320010
h2h4       2269413040
Ne2g1      2345960033
Ne2c3      2902361581
Ne2g3      2725063064
Ne2d4      2907846050
Ne2f4      2806058340
Nb1d2      1349053003
Nb1a3      1890833545
Nb1c3      2513874218
Bc4b5      2013859334
Bc4a6      1752476016
Bc4d5      1933421928
Bc4e6      2307811200
Bc4xf7+      81765044
Bc4d3      1780719048
Bc4b3      1711824192
Bc1d2      1979741418
Bc1e3      3020083840
Bc1f4      2353180659
Bc1g5      2279029333
Bc1h6      2220512706
Rh1g1      1983977087
Rh1f1      2220729140
Qd1d2      2339880427
Qd1d3      3536668777
Qd1d4      3418732701
Qd1d5      2670993689
Qd1d6      2202746795
Qd1xd7+     193879619
Ke1f1      2483161986
Ke1xf2     1701268892
Ke1d2      1152858513
----------------------
total     90554783562  (1951.23 seconds)
Oliperft 1.01 and frcperft 1.0 agree with JetChess; I know that i-perft 1.0 is buggy (I only wanted to test its speed), but the following fact surprised me: it gives the exact numbers for O-O, Kf1, Kxf2 and Kd2, while gives 559 nodes less for Rg1 and other 559 nodes less for Rf1... the rest of the moves are counted very badly.

Summarizing: it looks like qperft is wrong and has some hidden bugs. It would be good that Muller or anyone else can confirm this issue (and fix it, in the case I am right).

For those who want to know where this position comes from, it is a kind of the Urusov/Ponziani Gambit:

1.- e4, e5; 2.- Bc4, Nf6; 3.- d4, c6; 4.- dxe5, Nxe4; 5.- Ne2, Nxf2 (the position of perft test, with the idea 6.- Kxf2?, Qh4+, forking the king and the light bishop, winning a pawn); 6.- O-O!? (tempting to the greedy 6.- ..., Nxd1?? (which leads to a mate in two); 7.- Bxf7+, Ke7 (the only move); 8.- Bg5#... a beautiful miniature).

Regards from Spain.

Ajedrecista.
tvrzsky
Posts: 128
Joined: Sat Sep 23, 2006 7:10 pm
Location: Prague

Re: REPORT: wrong perft result by qperft.

Post by tvrzsky »

Hi, my engine seems to be in agreement with JetChess:

Code: Select all

rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6
 _______________________________
|   |///|   |///|   |///|   |///|
| r | n | b | q | k | b |   | r |
|___|___|___|___|___|___|___|___|
|///|   |///|   |///|   |///|   |
| p | p |   | p |   | p | p | p |
|___|___|___|___|___|___|___|___|
|   |///|   |///|   |///|   |///|
|   |   | p |   |   |   |   |   |
|___|___|___|___|___|___|___|___|
|///|   |///|   |///|   |///|   |
|   |   |   |   |[P]|   |   |   |
|___|___|___|___|___|___|___|___|
|   |///|   |///|   |///|   |///|
|   |   |[B]|   |   |   |   |   |
|___|___|___|___|___|___|___|___|
|///|   |///|   |///|   |///|   |
|   |   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|___|
|   |///|   |///|   |///|   |///|
|[P]|[P]|[P]|   |[N]| n |[P]|[P]|
|___|___|___|___|___|___|___|___|
|///|   |///|   |///|   |///|   |
|[R]|[N]|[B]|[Q]|[K]|   |   |[R]|
|___|___|___|___|___|___|___|___|

-------------------------------------------------------------------------------
perft(7)               SubtreePerft        InnerNodes
-------------------------------------------------------------------------------
01/42  Bc4xf7+           86,568,355         2,399,536       0.83s   2905.80kN/s
02/42  Qd1xd7+          207,937,563         6,442,546       2.90s   3107.63kN/s
03/42   Ke1xf2        1,701,268,892        41,731,246      19.33s   2540.50kN/s
04/42      O-O        2,291,266,832        59,076,658      44.95s   2306.20kN/s
05/42   Bc1-d2        2,107,363,662        57,353,686      66.73s   2633.48kN/s
06/42   Bc1-e3        3,184,524,390        76,330,609     100.32s   2272.44kN/s
07/42   Bc1-f4        2,482,656,228        63,264,159     126.11s   2453.00kN/s
08/42   Bc1-g5        2,400,385,594        58,841,962     150.69s   2394.23kN/s
09/42   Bc1-h6        2,344,263,758        59,807,557     176.23s   2342.48kN/s
10/42   Bc4-a6        1,855,061,374        50,684,287     196.28s   2528.00kN/s
11/42   Bc4-b3        1,816,240,296        50,419,516     216.33s   2514.53kN/s
12/42   Bc4-b5        2,130,713,616        56,958,047     239.01s   2511.69kN/s
13/42   Bc4-d3        1,886,965,922        52,741,918     258.58s   2695.65kN/s
14/42   Bc4-d5        2,046,941,872        55,030,025     280.20s   2545.10kN/s
15/42   Bc4-e6        2,444,185,312        64,287,142     307.43s   2361.16kN/s
16/42   Nb1-a3        2,002,068,159        53,493,354     329.37s   2437.92kN/s
17/42   Nb1-c3        2,655,487,727        66,340,463     357.30s   2376.17kN/s
18/42   Nb1-d2        1,435,627,351        42,973,858     372.70s   2790.11kN/s
19/42   Ne2-c3        3,057,530,890        75,521,696     405.37s   2311.45kN/s
20/42   Ne2-d4        3,061,284,388        74,403,251     437.33s   2328.55kN/s
21/42   Ne2-f4        2,949,871,106        72,750,300     468.18s   2358.41kN/s
22/42   Ne2-g1        2,354,927,176        61,986,369     493.72s   2427.34kN/s
23/42   Ne2-g3        2,865,273,204        70,686,740     524.34s   2308.23kN/s
24/42   Rh1-f1        2,220,729,699        57,550,527     549.42s   2295.27kN/s
25/42   Rh1-g1        1,983,977,646        53,560,702     570.95s   2487.66kN/s
26/42   Qd1-d2        2,481,769,422        63,129,435     597.96s   2337.38kN/s
27/42   Qd1-d3        3,719,739,001        86,078,016     637.14s   2196.90kN/s
28/42   Qd1-d4        3,598,056,747        82,912,653     675.56s   2158.36kN/s
29/42   Qd1-d5        2,815,305,249        67,691,535     706.66s   2176.77kN/s
30/42   Qd1-d6        2,314,600,161        54,028,278     732.84s   2063.75kN/s
31/42    a2-a4        2,548,648,372        64,275,411     759.43s   2417.35kN/s
32/42    b2-b4        2,263,311,424        58,536,007     783.63s   2419.20kN/s
33/42    g2-g4        2,033,046,400        54,572,071     806.05s   2434.64kN/s
34/42    h2-h4        2,387,827,889        61,436,012     831.56s   2407.93kN/s
35/42    a2-a3        2,245,837,704        58,816,526     855.64s   2443.30kN/s
36/42    b2-b3        2,166,557,328        57,705,339     879.12s   2457.08kN/s
37/42    c2-c3        2,411,002,727        63,167,942     904.89s   2451.63kN/s
38/42    e5-e6        2,461,806,026        64,636,087     933.44s   2264.11kN/s
39/42    g2-g3        1,981,011,243        53,489,028     955.17s   2461.33kN/s
40/42    h2-h3        2,217,212,927        58,351,441     979.10s   2439.10kN/s
41/42   Ke1-d2        1,152,858,513        37,013,472     992.03s   2863.96kN/s
42/42   Ke1-f1        2,483,161,986        64,248,646    1017.04s   2568.37kN/s
-------------------------------------------------------------------------------
total:               94,854,874,131     2,434,724,053    1017.04s   2393.92kN/s
-------------------------------------------------------------------------------
perft(7) = 94,854,874,131
Filip
Michel
Posts: 2272
Joined: Mon Sep 29, 2008 1:50 am

Re: REPORT: wrong perft result by qperft.

Post by Michel »

GnuChess also agrees

Code: Select all

setboard rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6 
HashKey=522e27173760599a
Repeat=0
FEN=rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6
white  KQkq
    +---+---+---+---+---+---+---+---+
  8 |*R*|*N*|*B*|*Q*|*K*|*B*|   |*R*|
    +---+---+---+---+---+---+---+---+
  7 |*P*|*P*| . |*P*| . |*P*|*P*|*P*|
    +---+---+---+---+---+---+---+---+
  6 |   | . |*P*| . |   | . |   | . |
    +---+---+---+---+---+---+---+---+
  5 | . |   | . |   | P |   | . |   |
    +---+---+---+---+---+---+---+---+
  4 |   | . | B | . |   | . |   | . |
    +---+---+---+---+---+---+---+---+
  3 | . |   | . |   | . |   | . |   |
    +---+---+---+---+---+---+---+---+
  2 | P | P | P | . | N |*N*| P | P |
    +---+---+---+---+---+---+---+---+
  1 | R | N | B | Q | K |   | . | R |
    +---+---+---+---+---+---+---+---+
      a   b   c   d   e   f   g   h
perft 7
Perft(7)=94854874131 time=8776.47s nps=277415
kongsian
Posts: 46
Joined: Thu Jun 15, 2006 11:21 am

Re: REPORT: wrong perft result by qperft.

Post by kongsian »

My perft.

Code: Select all

./perft --depth 7 --divide --fen "rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6" --size 1024
Hash table size = 1024 Mbytes.

+---+---+---+---+---+---+---+---+
|*r |*n |*b |*q |*k |*b |   |*r |
+---+---+---+---+---+---+---+---+
|*p |*p |   |*p |   |*p |*p |*p |
+---+---+---+---+---+---+---+---+
|   |   |*p |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   | P |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   | B |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+
| P | P | P |   | N |*n | P | P |
+---+---+---+---+---+---+---+---+
| R | N | B | Q | K |   |   | R |
+---+---+---+---+---+---+---+---+

rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6


Perft [7]:

1/42	a2a3	2245837704
2/42	b2b3	2166557328
3/42	c2c3	2411002727
4/42	g2g3	1981011243
5/42	h2h3	2217212927
6/42	e5e6	2461806026
7/42	a2a4	2548648372
8/42	b2b4	2263311424
9/42	g2g4	2033046400
10/42	h2h4	2387827889
11/42	Nb1d2	1435627351
12/42	Nb1a3	2002068159
13/42	Nb1c3	2655487727
14/42	Ne2g1	2354927176
15/42	Ne2c3	3057530890
16/42	Ne2g3	2865273204
17/42	Ne2d4	3061284388
18/42	Ne2f4	2949871106
19/42	Bc1d2	2107363662
20/42	Bc1e3	3184524390
21/42	Bc1f4	2482656228
22/42	Bc1g5	2400385594
23/42	Bc1h6	2344263758
24/42	Bc4b3	1816240296
25/42	Bc4d3	1886965922
26/42	Bc4b5	2130713616
27/42	Bc4d5	2046941872
28/42	Bc4a6	1855061374
29/42	Bc4e6	2444185312
30/42	Bc4xf7	86568355
31/42	Rh1f1	2220729699
32/42	Rh1g1	1983977646
33/42	Qd1d2	2481769422
34/42	Qd1d3	3719739001
35/42	Qd1d4	3598056747
36/42	Qd1d5	2815305249
37/42	Qd1d6	2314600161
38/42	Qd1xd7	207937563
39/42	Ke1f1	2483161986
40/42	Ke1d2	1152858513
41/42	Ke1xf2	1701268892
42/42	Ke1g1	2291266832

Node: 94854874131
Time: 106733
How about turning off hashing for qperft?

Kong Sian
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: REPORT: wrong perft result by qperft.

Post by sje »

Symbolic says:
[d]rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6[/d]

Code: Select all

[] sf rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6
[] emptran 7
Bb3 1,816,240,296
Bd2 2,107,363,662
Ba6 1,855,061,374
Bb5 2,130,713,616
Bd3 1,886,965,922
Bd5 2,046,941,872
Be6 2,444,185,312
Be3 3,184,524,390
Bxf7+ 86,568,355
Bf4 2,482,656,228
Bg5 2,400,385,594
Kd2 1,152,858,513
Bh6 2,344,263,758
Kxf2 1,701,268,892
Na3 2,002,068,159
Kf1 2,483,161,986
Nbc3 2,655,487,727
Nd2 1,435,627,351
Nd4 3,061,284,388
Nec3 3,057,530,890
Ng1 2,354,927,176
Nf4 2,949,871,106
Ng3 2,865,273,204
O-O 2,291,266,832
Qd2 2,481,769,422
Qd3 3,719,739,001
Qxd7+ 207,937,563
Qd5 2,815,305,249
Qd4 3,598,056,747
Qd6 2,314,600,161
Rg1 1,983,977,646
Rf1 2,220,729,699
a3 2,245,837,704
b3 2,166,557,328
a4 2,548,648,372
b4 2,263,311,424
c3 2,411,002,727
g3 1,981,011,243
e6 2,461,806,026
h3 2,217,212,927
g4 2,033,046,400
h4 2,387,827,889
Depth: 7   Count: 94,854,874,131   Elapsed: 66.0535  (1.43603e+09 Hz / 6.96364e-10 s)
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: REPORT: wrong perft result by qperft.

Post by Daniel Shawul »

Mine finished after awfully long time. It should be easy to spot the problem with a divide perft.

Code: Select all

perft 7
e1f2  1701268892
c4f7  86568355
d1d7  207937563
e1g1  2291266832
c2c3  2411002727
h2h3  2217212927
h2h4  2387827889
g2g3  1981011243
g2g4  2033046400
b2b3  2166557328
b2b4  2263311424
a2a3  2245837704
a2a4  2548648372
e5e6  2461806026
e2g3  2865273204
e2f4  2949871106
e2c3  3057530890
e2g1  2354927176
e2d4  3061284388
b1d2  1435627351
b1c3  2655487727
b1a3  2002068159
c1d2  2107363662
c1e3  3184524390
c1f4  2482656228
c1g5  2400385594
c1h6  2344263758
c4d5  2046941872
c4e6  2444185312
c4b3  1816240296
c4b5  2130713616
c4a6  1855061374
c4d3  1886965922
h1g1  1983977646
h1f1  2220729699
d1d2  2481769422
d1d3  3719739001
d1d4  3598056747
d1d5  2815305249
d1d6  2314600161
e1d2  1152858513
e1f1  2483161986
nodes 94854874131
time 20187.49 sec
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: REPORT: wrong perft result by qperft.

Post by Daniel Shawul »

It is definately a hash table bug.
After e5e6, without a hash table it gives correct results

Code: Select all

perft 6 "-2" "rnbqkb1r/pp1p1ppp/2p1P3/8/2B5/8/PPP1NnPP/RNBQK2R b KQkq - 0 6"

2. c6c5 moves =   65250953 ( 0.640 sec)
2. h7h6 moves =   74322298 ( 0.735 sec)
2. h7h5 moves =   78705132 ( 0.859 sec)
2. g7g6 moves =   78034448 ( 0.781 sec)
2. g7g5 moves =   66169827 ( 0.657 sec)
2. f7e6 moves =   64535721 ( 0.656 sec)
2. f7f6 moves =   54438728 ( 0.562 sec)
2. f7f5 moves =   64186383 ( 0.657 sec)
2. d7e6 moves =   86701509 ( 0.890 sec)
2. d7d6 moves =   67036802 ( 0.735 sec)
2. d7d5 moves =   82257295 ( 0.843 sec)
2. b7b6 moves =   72566559 ( 0.703 sec)
2. b7b5 moves =   76728327 ( 0.782 sec)
2. a7a6 moves =   70418560 ( 0.703 sec)
2. a7a5 moves =   77371240 ( 0.750 sec)
2. f2d3 moves =    7357733 ( 0.078 sec)
2. f2e4 moves =   75283737 ( 0.719 sec)
2. f2g4 moves =   67607241 ( 0.687 sec)
2. f2h3 moves =   56792704 ( 0.578 sec)
2. f2h1 moves =   46660634 ( 0.438 sec)
2. f2d1 moves =   42513258 ( 0.500 sec)
2. b8a6 moves =   82211968 ( 0.812 sec)
2. d8e7 moves =   62217713 ( 0.625 sec)
2. d8f6 moves =   91231153 ( 1.000 sec)
2. d8g5 moves =  105270469 ( 1.110 sec)
2. d8h4 moves =   83720856 ( 0.937 sec)
2. d8c7 moves =   80381152 ( 0.828 sec)
2. d8b6 moves =   78384048 ( 0.828 sec)
2. d8a5 moves =   21945709 ( 0.235 sec)
2. f8e7 moves =   75419103 ( 0.750 sec)
2. f8d6 moves =   96107199 ( 0.969 sec)
2. f8c5 moves =   88600632 ( 0.921 sec)
2. f8b4 moves =   15650634 ( 0.172 sec)
2. f8a3 moves =   83712650 ( 0.844 sec)
2. h8g8 moves =   74139349 ( 0.766 sec)
2. e8e7 moves =   47874302 ( 0.468 sec)
perft( 6)=   2461806026 (25.218 sec)
With a hash table wrong results

Code: Select all

perft 6 "H23" "-2" "rnbqkb1r/pp1p1ppp/2p1P3/8/2B5/8/PPP1NnPP/RNBQK2R b KQkq - 0 6"

2. c6c5 moves =   65256159 ( 0.312 sec)
2. h7h6 moves =   74327157 ( 0.391 sec)
2. h7h5 moves =   78710388 ( 0.390 sec)
2. g7g6 moves =   78039114 ( 0.375 sec)
2. g7g5 moves =   66173473 ( 0.328 sec)
2. f7e6 moves =   64535721 ( 0.297 sec)
2. f7f6 moves =   54441466 ( 0.250 sec)
2. f7f5 moves =   64191163 ( 0.297 sec)
2. d7e6 moves =   86701509 ( 0.375 sec)
2. d7d6 moves =   67046267 ( 0.281 sec)
2. d7d5 moves =   82266683 ( 0.360 sec)
2. b7b6 moves =   72570447 ( 0.265 sec)
2. b7b5 moves =   76734004 ( 0.282 sec)
2. a7a6 moves =   70423024 ( 0.250 sec)
2. a7a5 moves =   77376491 ( 0.265 sec)
2. f2d3 moves =    7357733 ( 0.078 sec)
2. f2e4 moves =   75289295 ( 0.250 sec)
2. f2g4 moves =   67612137 ( 0.204 sec)
2. f2h3 moves =   56797036 ( 0.156 sec)
2. f2h1 moves =   46664359 ( 0.140 sec)
2. f2d1 moves =   42517678 ( 0.141 sec)
2. b8a6 moves =   82217426 ( 0.234 sec)
2. d8e7 moves =   62217717 ( 0.141 sec)
2. d8f6 moves =   91234424 ( 0.250 sec)
2. d8g5 moves =  105274408 ( 0.250 sec)
2. d8h4 moves =   83723867 ( 0.203 sec)
2. d8c7 moves =   80384080 ( 0.125 sec)
2. d8b6 moves =   78387062 ( 0.156 sec)
2. d8a5 moves =   21945709 ( 0.063 sec)
2. f8e7 moves =   75419070 ( 0.172 sec)
2. f8d6 moves =   96110664 ( 0.187 sec)
2. f8c5 moves =   88603987 ( 0.172 sec)
2. f8b4 moves =   15650634 ( 0.047 sec)
2. f8a3 moves =   83715833 ( 0.156 sec)
2. h8g8 moves =   74144265 ( 0.047 sec)
2. e8e7 moves =   47874382 ( 0.047 sec)
perft( 6)=   2461934832 ( 7.937 sec)
User avatar
JuLieN
Posts: 2949
Joined: Mon May 05, 2008 12:16 pm
Location: Bordeaux (France)
Full name: Julien Marcel

Re: REPORT: wrong perft result by qperft.

Post by JuLieN »

Wow, this position is GOLD! Thanks, Jesús!

It appears that my engine also has a bug that no other position caught: it reports a wrong number of moved for e5-e6 (shorter by 1520 nodes):
Predateur v2.2.1_x64 ©2012-02-08 by Julien MARCEL
ucinewgame
position moves e2e4 e7e5 f1c4 g8f6 d2d4 c7c6 d4e5 f6e4 g1e2 e4f2
perft 7
a2a3 : 2245837704
a2a4 : 2548648372
b2b3 : 2166557328
b2b4 : 2263311424
c2c3 : 2411002727
e5e6 : 2461804506
g2g3 : 1981011243
g2g4 : 2033046400
h2h3 : 2217212927
h2h4 : 2387827889
b1a3 : 2002068159
b1c3 : 2655487727
b1d2 : 1435627351
e2c3 : 3057530890
e2d4 : 3061284388
e2f4 : 2949871106
e2g3 : 2865273204
e2g1 : 2354927176
c1d2 : 2107363662
c1e3 : 3184524390
c1f4 : 2482656228
c1g5 : 2400385594
c1h6 : 2344263758
c4d5 : 2046941872
c4e6 : 2444185312
c4f7 : 86568355
c4d3 : 1886965922
c4b3 : 1816240296
c4b5 : 2130713616
c4a6 : 1855061374
h1g1 : 1983977646
h1f1 : 2220729699
d1d2 : 2481769422
d1d3 : 3719739001
d1d4 : 3598056747
d1d5 : 2815305249
d1d6 : 2314600161
d1d7 : 207937563
e1f1 : 2483161986
e1d2 : 1152858513
e1f2 : 1701268892
e1g1 : 2291266832
Nombre de noeuds : 94854872611 ; Temps : 7129.910s ; vitesse : 13303796 nps
This position should be in any wiki, as no other position I tried ever reported a wrong number of nodes!

I guess this has something to do with promotion, as the e pawn is the only one that can promote in the 7 upcomming plies...
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: REPORT: wrong perft result by qperft.

Post by hgm »

I can confirm there was a hash bug on under-promotion in qperft.

Under-promotions were added as an afterthought in qperft (Joker does not have under-promotions), by looping 4 times over the {MakeMove, Recurse, Unmake} part. But the special part of the moves is made before, as the code looks like:

Code: Select all

  MakeSpecial();
  UpdateKey();
  HashProbe();
  do {
    MakeMove();
    Perft(n-1);
    UnMake();
    HashStore();
    RestoreKey();
  } while(NextPromoPiece());
  RestoreKey();
For the key I used copy-modify, so the RestoreKey just puts back the original value from before the update. The RestoreKey() within the loop was a spurious one, that should not have been there at all (it was actually hidden in the HashStore() code). So the three under-promotions were all searched with the same key as the position before the promotion, and thus, more importantly, with the same key as each other.

After I deleted the spurious RestoreKey(), it still did not work, because NextPromoPiece() did not alter the key, and the UpdateKey was before the loop.

I did not make a new version yet, but invalidating the key by just adding something to it in NextPromoPiece() did produce the correct perft(7).

Thanks for reporting this.
User avatar
JuLieN
Posts: 2949
Joined: Mon May 05, 2008 12:16 pm
Location: Bordeaux (France)
Full name: Julien Marcel

Re: REPORT: wrong perft result by qperft.

Post by JuLieN »

There, bug found and corrected. Now Prédateur agrees with JetChess too. :) It's quite astonishing to find a bug in the move generation when I thought it was bug free for years!

Maybe I should tell what the bug was, in case someone else has the same problem in his engine?

After going deeper into the tree to see where the node count was starting to diverge, I noticed that when the e pawn was promoted to a rook and that this rook was later captured by the black queen then Prédateur wouldn't consider castling on the king side anymore. So I looked into my MakeMove routine and found a bug there (in pseudocode):

Code: Select all

if (Capture) and (CapturedPiece.type = rook) then begin
  if (Board[to_square] = WhiteRook1) then WhiteQueenCastle := false
  else WhiteKingCastle := false; // This is where the bug is!!!
end;
The commented line is where the bug was: I falsely assumed that the captured rook would be the other one on the starting position board (WhiteRook2), while this rook was actually WhitePawn5 turned into a rook, which wrongly triggered the loss of the king-side castling flag.

The correct pseudo-code is:

Code: Select all

if (Capture) and (CapturedPiece.type = rook) then begin
  if (Board[to_square] = WhiteRook1) then WhiteQueenCastle := false
  else if (Board[to_square] = WhiteRook2) then  WhiteKingCastle := false;
end;
So the missing 1520 moves out of 94 billions were all the king-side castles moves lost that way.

So this position was very interesting because it was a position where:
1- the game is early so the king still hasn't castled but can still do it on both sides;
2- still, a pawn is ready to get promoted.

As the perft procedure up to a depth 7 in this position takes some time, here is a more handy position (a few plies later in the tree) that still matches those two criteria above:

[d]rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8
(Here, a perft 3 is sufficient to detect the class of bugs described above)

Is your perft (with hash) having problems with this position too, HG?

Thanks again for this position, Jesús! :)
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]