Skip to content

Commit 9eccba7

Browse files
atumanianmcostalba
authored andcommitted
Fix the pawn hash failure when the pawn key is 0
This patch fixed bugs official-stockfish#859 and official-stockfish#882. At initialization we generate a new random key (Zobrist::noPawns). It's added to the pawn key of all positions, so that the pawn key of a pawnless position is no longer 0. STC: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 21307 W: 3738 L: 3618 D: 13951 LTC: LLR: 2.94 (-2.94,2.94) [-3.00,1.00] Total: 45270 W: 5737 L: 5648 D: 33885 No functional change.
1 parent ca464fc commit 9eccba7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/position.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace Zobrist {
4545
Key psq[PIECE_NB][SQUARE_NB];
4646
Key enpassant[FILE_NB];
4747
Key castling[CASTLING_RIGHT_NB];
48-
Key side;
48+
Key side, noPawns;
4949
}
5050

5151
namespace {
@@ -145,6 +145,7 @@ void Position::init() {
145145
}
146146

147147
Zobrist::side = rng.rand<Key>();
148+
Zobrist::noPawns = rng.rand<Key>();
148149
}
149150

150151

@@ -331,7 +332,8 @@ void Position::set_check_info(StateInfo* si) const {
331332

332333
void Position::set_state(StateInfo* si) const {
333334

334-
si->key = si->pawnKey = si->materialKey = 0;
335+
si->key = si->materialKey = 0;
336+
si->pawnKey = Zobrist::noPawns;
335337
si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO;
336338
si->psq = SCORE_ZERO;
337339
si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove);

0 commit comments

Comments
 (0)