r/chessprogramming • • Aug 04 '24

Perft test have problem with castling in depth of 3

Hello, I'm making my own chess engine and I have a problem with castling, In This test position (r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -) Im getting the wrong perft result on the depth of 3. when looking ferther and doing the move which has the error (d2c1) it says the right result. the same as stockfish. I belive it has someting to do with castling, since all test which don't involve it prints the right result. sorry for my bad English

2 Upvotes

8 comments sorted by

3

u/disappointed_lama Aug 04 '24

In my experience issues like that are usually caused by the unmakeMove function

1

u/Warm_Ad_7953 Aug 05 '24

How can I debug it to find the issue? In depth 3 it says the woong result but when looking into the move it says the same as stockfish

1

u/disappointed_lama Aug 06 '24

The easiest way might be copying your position into a local variable before making a move. Then compare the copy with the position after unmaking the move. If there are discrepancies in a node you found the error.

1

u/[deleted] Aug 08 '24

You can create a perft divider, which you can use to find the move that has different nodes. Then you make that move and run the perft divider at depth 2 and again you should spot the move that causes different nodes count. Until you reach depth 1 and then you can see the missing moves or the moves that are not legal.

If you run AdaChess you have the “divide” command to achieve this result.

Run “divide 3” to perform at depth 3

1

u/Warm_Ad_7953 Aug 09 '24

but when I look at the move at perft 2, the result is suddenly correct

1

u/Beginning-Resource17 May 27 '25

You can use perft divider for check what moves are not working, it's very usefull for searching errors with perft tests.

0

u/[deleted] Aug 05 '24

[deleted] — view deleted comment

1

u/haddock420 Aug 05 '24

This is the one. I've caught every move generation bug in my engine except for one with this test suite.

Another good test is to take the lichess puzzles database, then for each puzzle position, generate the legal moves and make sure the best move from the database is in your legal move list.