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

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

Post by aaronmell »

Ran some tests using my makemove function vs loading the board from a FEN. Same results.
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 »

I went ahead and added this to my perft function. There was no discrepancies after making and then unmaking a board.
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 »

xmas79 wrote:Are you using some sort of "guards" in your debug code? Asserts? Board check in make/unmake? move validity?
Its a pseudo-legal generator, but I am checking for valid checks in my perft function. I haven't added any logic to prevent castling through a check yet though, although I am not enough moves deep for that to matter.

I only have a few asserts in perft to verify that my gamestate matches after make/unmake. But I have a large number of unit tests to help validate things are working correctly, unfortunately, none of my unit tests are capturing this issue :D.
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 »

bob wrote: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.
I set it on a double pawn move and I am clearing it at the beginning of each move.
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 »

After 1. d4 c6 I see this when running divide 3
Sharper Mine
a2a3 546 A2A3 546
a2a4 586 A2A4 586
b1a3 544 B1A3 543
b1c3 604 B1C3 603
b1d2 479 B1D2 478
b2b3 586 B2B3 586
b2b4 610 B2B4 610
c1d2 583 C1D2 582
c1e3 546 C1E3 545
c1f4 660 C1F4 659
c1g5 615 C1G5 614
c1h6 563 C1H6 562
c2c3 608 C2C3 608
c2c4 606 C2C4 606
d1d2 603 D1D2 602
d1d3 864 D1D3 863
d4d5 604 D4D5 604
e1d2 486 E1D2 485
e2e3 687 E2E3 687
e2e4 767 E2E4 767
f2f3 547 F2F3 547
f2f4 509 F2F4 509
g1f3 607 G1F3 606
g1h3 566 G1H3 565
g2g3 586 G2G3 586
g2g4 587 G2G4 587
h2h3 546 H2H3 546
h2h4 586 H2H4 586

So I am off by one on all of my non-pawn moves at this point. And if I play for example

1. d4 c6 2. Bd2

a7a5 28 A7A5 28
a7a6 28 A7A6 28
b7b5 28 B7B5 28
b7b6 28 B7B6 28
b8a6 28 B8A6 28
c6c5 29 C6C5 29
d7d5 27 D7D5 27
d7d6 28 D7D6 28
d8a5 23 D8A5 23
d8b6 28 D8B6 28
d8c7 28 D8C7 28
e7e5 29 E7E5 29
e7e6 28 E7E6 28
f7f5 28 F7F5 28
f7f6 28 F7F6 28
g7g5 27 G7G5 27
g7g6 28 G7G6 28
g8f6 28 G8F6 28
g8h6 28 G8H6 28
h7h5 28 H7H5 28
h7h6 28 H7H6 28

Everything lines back up against
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 »

I seem to have discovered my bug. I had several issues

1. Shallow copy of my object when comparing make and unmake, would never fail
2. Had some copy/paste errors in my Unmake Logic, was using Capture instead of UnCapture.
3. unit tests weren't robust enough to catch the issue. My testing of the unmake move was not sufficient to catch the issue.

Perft is still failing, so its on to the next issue, but I feel good having fixed at least one issue.
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 »

aaronmell wrote:
xmas79 wrote:Are you using some sort of "guards" in your debug code? Asserts? Board check in make/unmake? move validity?
Its a pseudo-legal generator, but I am checking for valid checks in my perft function. I haven't added any logic to prevent castling through a check yet though, although I am not enough moves deep for that to matter.

I only have a few asserts in perft to verify that my gamestate matches after make/unmake. But I have a large number of unit tests to help validate things are working correctly, unfortunately, none of my unit tests are capturing this issue :D.
you should have at least a ton of assserts...they can be very effective... and also dont check only for your board consistency,generate a scratch new board by loading the fen corresponsing to current position after each make/unmame and the check if their board status are consistent with thr incremental one

btw why dont you dump 'em all?they are only around 500 moves you could easily check which one is missing...