UPDATE ON QUESTION:
I've revealed that hash keys are wrong when null move pruning occurs.
But the strange thing is that when I was allowing to do null move several times in the row
this wasn't so, I mean hash keys were correct, so now with making null move only if
previous move wasn't null move I;m starting getting these incorrect hash values.
Here's the code for null move pruning:
Code: Select all
// previous move wasn't null move
if (nullMove) {
// null move pruning
if ( searchPly && depth > 2 && staticEval >= beta) {
let correct = generateHashKey();
if (hashKey != correct) {
// gives wrong hash keys here!
console.log('wrong:', hashKey, ' correct:', correct, ' ep:', enpassant);
}
makeNullMove();
score = -negamax(-beta, -beta + 1, depth - 1 - 2, NO_NULL);
takeNullMove();
if (timing.stopped == 1) return 0;
if (score >= beta) return beta;
}
...
}
Here's the code for make/take null move:
Code: Select all
// make null move
function makeNullMove() {
// backup current board state
moveStack.push({
move: 0,
capturedPiece: 0,
side: side,
enpassant: enpassant,
castle: castle,
fifty: fifty,
hash: hashKey,
});
if (enpassant != noEnpassant) hashKey ^= pieceKeys[enpassant];
enpassant = noEnpassant;
fifty = 0;
side ^= 1;
hashKey ^= sideKey;
}
// take null move
function takeNullMove() {
// restore board state
side = moveStack[moveStack.length - 1].side;
enpassant = moveStack[moveStack.length - 1].enpassant;
castle = moveStack[moveStack.length - 1].castle;
fifty = moveStack[moveStack.length - 1].fifty;
hashKey = moveStack[moveStack.length - 1].hashKey;
moveStack.pop();
}
Please note that I do take care about hashing side and enpassant square if it's not equal to no square
but for some reason hash keys are getting malformed after null move pruning.
If I comment out null move pruning code hash keys are correct again.
How can I debug my hash keys within null move pruning?
I just can't realize which parameter wasn't XORed with hash keys,
can I somehow manually reproduce wrong hashes without running search to figure out what's going wrong?