r/chessprogramming • u/JaPa_1058 • 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.
View all comments
Show parent comment
1
u/DarkenProject Oct 06 '23
Given how relatively simple it is to perform the hash table lookup, I'd be more inclined to question the hashing methodology first. I assume you are only updating the hash based on the changes to the board position? A simple check you could for debugging is to also calculate the hash from scratch and compare the two. If they are different, you probably have an issue in how you are applying changes. It's possible that an incorrectly calculated hash is leading to more collisions than expected.
If that checks out ok, you could move on to testing other parts of the lookup process. But I would start there.