I'm making a chess program in Unity and I've made a perft function to find the bugs in my move generator. I've downloaded Stockfish to compare the results.
From the starting chess position, with a depth of 3, my results match with Stockfish's for the most part. The only difference is after black's knight moves.
Here's Stockfish's result:
a2a3: 380
b2b3: 420
c2c3: 420
d2d3: 539
e2e3: 599
f2f3: 380
g2g3: 420
h2h3: 380
a2a4: 420
b2b4: 421
c2c4: 441
d2d4: 560
e2e4: 600
f2f4: 401
g2g4: 421
h2h4: 420
b1a3: 400
b1c3: 440
g1f3: 440
g1h3: 400
Nodes searched: 8902
And here are my results:
a2a3: 380
b2b3: 420
c2c3: 420
d2d3: 539
e2e3: 599
f2f3: 380
g2g3: 420
h2h3: 380
a2a4: 420
b2b4: 421
c2c4: 441
d2d4: 560
e2e4: 600
f2f4: 401
g2g4: 421
h2h4: 420
b1a3: 420
b1c3: 460
g1f3: 460
g1h3: 420
Nodes searched: 8982
My algorithm is generating a total of exactly 20 more moves than Stockfish after each of black's knight move.
My question is, how can I use these results to find what illegal moves my program is considering legal? What's the fastest way to debug my algorithm given these or any future test results?
I couldn't find anything else online, that's why I'm asking here.
Follow the following procedure.
position startpos moves b1a3
, then send a perft 2 command. Notice the depth is reduced from depth 3 to depth 2. We reduce it because we push the move. For sf and your engine:Then record the moves the way you did in the post,
These are legal move generation issues, so you have to review your move generations, makemove and unmakemove functions. You have knight move issues so probably your knight move offsets are incorrect. Also check your attack function.
Also in your code add some asserts everywhere like a white piece cannot capture another white piece, the
to square
of the move is within the 64-board squares and others.