Perft Issue. Divide is correct when depth is less than 5

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

aaronmell
Posts: 14
Joined: Sat Aug 30, 2014 2:32 am

Perft Issue. Divide is correct when depth is less than 5

Post by aaronmell »

Hi,

I am writing a chess engine, and I seem to be having an issue that I just cannot put my finger on. From the initial position, my move count is correct at a depth of 4, and fails at a depth of 5.

So I write a divide function and start debugging. I go to the first position that is wrong, and run the test with a depth of 4, and the count is correct. When I increase it back to 5, I get another failure. I got about 3 moves deep into the tree, and they all pass when my depth is less that 5.


Depth 4 Nodes 197281 Captures 1539 E.P 0 Castles 0 Promotions 0 Checks 469

Depth 3 is correct. Depth 5 is off. My Count is correct at depth 4, but my captures is off by 37.

Here is a comparison of divides. The good output is first, followed by mine.
Move Nodes
b1c3 234656
b1a3 198572
g1h3 198502
g1f3 233491
a2a3 181046
a2a4 217832
b2b3 215255
b2b4 216145
c2c3 222861
c2c4 240082
d2d3 328511
d2d4 361790
e2e3 402988
e2e4 405385
f2f3 178889
f2f4 198473
g2g3 217210
g2g4 214048
h2h3 181044
h2h4 218829
Nodes: 4865609

Move Nodes
A2A3 181046
A2A4 217832
B2B3 215255
B2B4 215759
C2C3 222308
C2C4 241898
D2D3 329160
D2D4 362649
E2E3 402144
E2E4 405368
F2F3 178889
F2F4 198250
G2G3 216673
G2G4 213346
H2H3 180131
H2H4 217743
B1A3 197578
B1C3 233501
G1F3 233217
G1H3 197513
Total Nodes: 4860260


Anyone have an idea of what I could investigate next?
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: Perft Issue. Divide is correct when depth is less than 5

Post by matthewlai »

aaronmell wrote:Hi,

I am writing a chess engine, and I seem to be having an issue that I just cannot put my finger on. From the initial position, my move count is correct at a depth of 4, and fails at a depth of 5.

So I write a divide function and start debugging. I go to the first position that is wrong, and run the test with a depth of 4, and the count is correct. When I increase it back to 5, I get another failure. I got about 3 moves deep into the tree, and they all pass when my depth is less that 5.


Depth 4 Nodes 197281 Captures 1539 E.P 0 Castles 0 Promotions 0 Checks 469

Depth 3 is correct. Depth 5 is off. My Count is correct at depth 4, but my captures is off by 37.

Here is a comparison of divides. The good output is first, followed by mine.
Move Nodes
b1c3 234656
b1a3 198572
g1h3 198502
g1f3 233491
a2a3 181046
a2a4 217832
b2b3 215255
b2b4 216145
c2c3 222861
c2c4 240082
d2d3 328511
d2d4 361790
e2e3 402988
e2e4 405385
f2f3 178889
f2f4 198473
g2g3 217210
g2g4 214048
h2h3 181044
h2h4 218829
Nodes: 4865609

Move Nodes
A2A3 181046
A2A4 217832
B2B3 215255
B2B4 215759
C2C3 222308
C2C4 241898
D2D3 329160
D2D4 362649
E2E3 402144
E2E4 405368
F2F3 178889
F2F4 198250
G2G3 216673
G2G4 213346
H2H3 180131
H2H4 217743
B1A3 197578
B1C3 233501
G1F3 233217
G1H3 197513
Total Nodes: 4860260


Anyone have an idea of what I could investigate next?
Depth 5 is the first ply that has en passant. Maybe it's something to do with that?

If divide is fine and perft is bad, that suggest problem in make/unmake logic.

Are you restoring en passant rights?
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
Richard Allbert
Posts: 792
Joined: Wed Jul 19, 2006 9:58 am

Re: Perft Issue. Divide is correct when depth is less than 5

Post by Richard Allbert »

Hi Aaron

Do the same for the position after d2d4 (one of the differences in your list above) - use a program like sharper to get the divide output, this time to depth 4.

Repeat the process until you get to depth one and you'll find the bug pretty quickly.
aaronmell
Posts: 14
Joined: Sat Aug 30, 2014 2:32 am

Re: Perft Issue. Divide is correct when depth is less than 5

Post by aaronmell »

That's what I tried. When I run Divide at depth 4 on one of the difference on the list everything is correct. If I bump it back up to 5 the results are off again.
aaronmell
Posts: 14
Joined: Sat Aug 30, 2014 2:32 am

Re: Perft Issue. Divide is correct when depth is less than 5

Post by aaronmell »

Did some additional testing this morning. I see the behavior when I make a non-pawn move. So if I move a knight, the divide function looks correct. It was occurring for both knight moves and bishop moves. Its feeling like I have a state issue with unmake possibly
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Perft Issue. Divide is correct when depth is less than 5

Post by cdani »

Another dirty but effective way for some bugs, it's to save the position in each iteration, and compare it after undoing each move.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Perft Issue. Divide is correct when depth is less than 5

Post by tpetzke »

When you do your depth 4 divide on the difference do you use your makeMove function to get to that new starting position or do you just setup the board from scratch with the new position, if the later do the first.

Thomas...
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine
aaronmell
Posts: 14
Joined: Sat Aug 30, 2014 2:32 am

Re: Perft Issue. Divide is correct when depth is less than 5

Post by aaronmell »

ooooh, thats a good idea. I've been loading the gamestate from Fen, not playing the moves out using makeMove. I'll give that a shot when I get some time.
xmas79
Posts: 286
Joined: Mon Jun 03, 2013 7:05 pm
Location: Italy

Re: Perft Issue. Divide is correct when depth is less than 5

Post by xmas79 »

Are you using some sort of "guards" in your debug code? Asserts? Board check in make/unmake? move validity?
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Perft Issue. Divide is correct when depth is less than 5

Post by bob »

One question, just to be sure, after I have read the other suggestions.

EP status. when you play e4 on the first move, you do NOT set any EP status I assume? Since there is no black pawn at f4/d4 no EP capture is possible. But assuming you do, do you immediately clear the ep flag after black makes a move, since he can either ep capture or the choice goes away? If you keep it and forget to clear it, that could cause a problem. e4 d5 h3 d4 could leave an ep capture possible which would be wrong... although not until depth=6 it would seem. But such a bug might have a way of breaking something in an unexpected way.