si->key ^= Zobrist::castling[si->castlingRights];
- for (Bitboard b = pieces(PAWN); b; )
- {
- Square s = pop_lsb(&b);
- si->pawnKey ^= Zobrist::psq[piece_on(s)][s];
- }
-
- for (Piece pc : Pieces)
- for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
- si->materialKey ^= Zobrist::psq[pc][cnt];
+ for (Color c = WHITE; c <= BLACK; ++c)
+ for (PieceType pt = PAWN; pt <= KING; ++pt)
+ {
+ Piece pc = make_piece(c, pt);
- if (pt != PAWN && pt != KING)
- si->nonPawnMaterial[c] += pieceCount[pc] * PieceValue[MG][pc];
+
+ for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
+ si->materialKey ^= Zobrist::psq[pc][cnt];
+
+ if (piece_drops())
+ si->key ^= Zobrist::inHand[pc][pieceCountInHand[c][pt]];
+ }
+
+ if (max_check_count())
+ for (Color c = WHITE; c <= BLACK; ++c)
+ si->key ^= Zobrist::checks[c][si->checksGiven[c]];
}