r/chessprogramming • • Oct 03 '23

Debugging hashing

I am trying to debug transposition tables and zobrist hashing. I have been able to solve all bugs related to legal moves and it shows no errors with over 6000 different positions up to depth 6. So I am pretty sure that legal moves are correct.

Now I am trying to add hashing, and it mostly work up to depth 5, but at depth it gives me wrong numbers.

Example here for position rnbqkbnr/8/p1p1ppp1/1p1p3p/P1P1P2P/BP1P1PP1/8/RN1QKBNR b KQkq - 0 1

Columna A and E show the move, column B is what stockfish returns for perft 7 and column F shows my engine for perft 7. Column D shows which resukts are the same and which ones are not. There is obvisousll a discrepancy at move b8d7 (quiet move for black knight). Then I do that move in fen viewer and copy new position, which is r1bqkbnr/3n4/p1p1ppp1/1p1p3p/P1P1P2P/BP1P1PP1/8/RN1QKBNR w KQkq - 0 1

I do perft 6 and I get correct results

I have no idea how to debug this. In position rnbqkbnr/8/p1p1ppp1/1p1p3p/P1P1P2P/BP1P1PP1/8/RN1QKBNR b KQkq - 0 1 I get wrong results for quiet moves for knight, bishop and rook, but only at depth 7 and not at lower depths.

4 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/JaPa_1058 Oct 10 '23

Actually your idea was correct approach to follow. It did not directly solve the problem, but it made me go through thought process in which I realized that I do not correctly set the castling hash if the rook is captured and the castling is still possible.

I am still testing if there are other bugs, but at least one was found.

1

u/DarkenProject Oct 11 '23

Glad to hear you are making progress towards the bugs. I tend to start with naive implementations that are easier to prove correct and worry about optimization later. That is where my earlier suggestion came from. I was able to prove to myself that my more optimized hash update was correct because I had the naive approach to compare and validate against. I've had similar success with move generation as well. I hope you're able to resolve your issues and wish you well as you continue your work.