Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove two xors by setting the hash keys for unreachable squares to zero #5754

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ void Position::init() {
for (Piece pc : Pieces)
for (Square s = SQ_A1; s <= SQ_H8; ++s)
Zobrist::psq[pc][s] = rng.rand<Key>();
// pawns on these squares will promote
std::fill_n(Zobrist::psq[W_PAWN] + SQ_A8, 8, 0);
std::fill_n(Zobrist::psq[B_PAWN], 8, 0);

for (File f = FILE_A; f <= FILE_H; ++f)
Zobrist::enpassant[f] = rng.rand<Key>();
Expand Down Expand Up @@ -380,7 +383,7 @@ void Position::set_state() const {

for (Piece pc : Pieces)
for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
st->materialKey ^= Zobrist::psq[pc][cnt];
st->materialKey ^= Zobrist::psq[pc][8 + cnt];
}


Expand Down Expand Up @@ -780,7 +783,7 @@ void Position::do_move(Move m,
remove_piece(capsq);

k ^= Zobrist::psq[captured][capsq];
st->materialKey ^= Zobrist::psq[captured][pieceCount[captured]];
st->materialKey ^= Zobrist::psq[captured][8 + pieceCount[captured]];

// Reset rule 50 counter
st->rule50 = 0;
Expand Down Expand Up @@ -844,10 +847,10 @@ void Position::do_move(Move m,
dp.dirty_num++;

// Update hash keys
k ^= Zobrist::psq[pc][to] ^ Zobrist::psq[promotion][to];
st->pawnKey ^= Zobrist::psq[pc][to];
// Zobrist::psq[pc][to] is zero, so we don't need to clear it
k ^= Zobrist::psq[promotion][to];
st->materialKey ^=
Zobrist::psq[promotion][pieceCount[promotion] - 1] ^ Zobrist::psq[pc][pieceCount[pc]];
Zobrist::psq[promotion][8 + pieceCount[promotion] - 1] ^ Zobrist::psq[pc][8 + pieceCount[pc]];

if (promotionType <= BISHOP)
st->minorPieceKey ^= Zobrist::psq[promotion][to];
Expand Down
Loading