|
|
|
|
@@ -63,7 +63,7 @@ impl ZobristKeys {
|
|
|
|
|
|
|
|
|
|
while bb != 0 {
|
|
|
|
|
let square = lsb(bb);
|
|
|
|
|
hash ^= self.piece_square_color[square][piece.piece_type.idx()][piece.color.idx()];
|
|
|
|
|
hash ^= self.piece_square_color[square][piece.piece_type][piece.color];
|
|
|
|
|
bb &= bb - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -73,7 +73,7 @@ impl ZobristKeys {
|
|
|
|
|
|
|
|
|
|
while bb != 0 {
|
|
|
|
|
let square = lsb(bb);
|
|
|
|
|
hash ^= self.piece_square_color[square][piece.piece_type.idx()][piece.color.idx()];
|
|
|
|
|
hash ^= self.piece_square_color[square][piece.piece_type][piece.color];
|
|
|
|
|
bb &= bb - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -82,8 +82,8 @@ impl ZobristKeys {
|
|
|
|
|
hash ^= self.side_to_move
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hash ^= self.castling_ability[board.state.castling_ability[0].idx()][0];
|
|
|
|
|
hash ^= self.castling_ability[board.state.castling_ability[1].idx()][1];
|
|
|
|
|
hash ^= self.castling_ability[board.state.castling_ability[0]][0];
|
|
|
|
|
hash ^= self.castling_ability[board.state.castling_ability[1]][1];
|
|
|
|
|
|
|
|
|
|
if let Some(ep) = board.state.en_passant_square {
|
|
|
|
|
hash ^= self.en_passant[square::to_file(ep)];
|
|
|
|
|
@@ -125,16 +125,16 @@ impl ZobristHash {
|
|
|
|
|
new_castling_ability: [Castle; 2],
|
|
|
|
|
) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.castling_ability[old_castling_ability[0].idx()][0];
|
|
|
|
|
self.hash ^= keys.castling_ability[old_castling_ability[1].idx()][1];
|
|
|
|
|
self.hash ^= keys.castling_ability[new_castling_ability[0].idx()][0];
|
|
|
|
|
self.hash ^= keys.castling_ability[new_castling_ability[1].idx()][1]
|
|
|
|
|
self.hash ^= keys.castling_ability[old_castling_ability[0]][0];
|
|
|
|
|
self.hash ^= keys.castling_ability[old_castling_ability[1]][1];
|
|
|
|
|
self.hash ^= keys.castling_ability[new_castling_ability[0]][0];
|
|
|
|
|
self.hash ^= keys.castling_ability[new_castling_ability[1]][1]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update_quiet(&mut self, src: usize, dst: usize, piece_at_src: PieceType, color: Color) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][piece_at_src.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_src.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][piece_at_src][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_src][color];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update_capture(
|
|
|
|
|
@@ -146,17 +146,16 @@ impl ZobristHash {
|
|
|
|
|
color: Color,
|
|
|
|
|
) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][piece_at_src.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_src.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_dst.idx()][color.opponent().idx()]
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][piece_at_src][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_src][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_dst][color.opponent()]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update_en_passant(&mut self, src: usize, dst: usize, ep_capture: usize, color: Color) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][PieceType::Pawn.idx()][color.idx()];
|
|
|
|
|
self.hash ^=
|
|
|
|
|
keys.piece_square_color[ep_capture][PieceType::Pawn.idx()][color.opponent().idx()]
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][PieceType::Pawn][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[ep_capture][PieceType::Pawn][color.opponent()]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update_double_push(
|
|
|
|
|
@@ -167,8 +166,8 @@ impl ZobristHash {
|
|
|
|
|
new_en_passant_target: Option<usize>,
|
|
|
|
|
) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][PieceType::Pawn.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][PieceType::Pawn][color];
|
|
|
|
|
|
|
|
|
|
if let Some(new_en_passant) = new_en_passant_target {
|
|
|
|
|
self.hash ^= keys.en_passant[square::to_file(new_en_passant)];
|
|
|
|
|
@@ -177,8 +176,8 @@ impl ZobristHash {
|
|
|
|
|
|
|
|
|
|
pub fn update_promotion(&mut self, src: usize, dst: usize, promote: &Promote, color: Color) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][promote.into_piece_type().idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][promote.into_piece_type()][color];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update_promotion_capture(
|
|
|
|
|
@@ -190,9 +189,9 @@ impl ZobristHash {
|
|
|
|
|
color: Color,
|
|
|
|
|
) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_dst.idx()][color.opponent().idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][promote.into_piece_type().idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][PieceType::Pawn][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_dst][color.opponent()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][promote.into_piece_type()][color];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update_castle(
|
|
|
|
|
@@ -205,10 +204,10 @@ impl ZobristHash {
|
|
|
|
|
color: Color,
|
|
|
|
|
) {
|
|
|
|
|
let keys = zobrist_keys();
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][piece_at_src.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_src.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[rook_src][PieceType::Rook.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[rook_dst][PieceType::Rook.idx()][color.idx()];
|
|
|
|
|
self.hash ^= keys.piece_square_color[src][piece_at_src][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[dst][piece_at_src][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[rook_src][PieceType::Rook][color];
|
|
|
|
|
self.hash ^= keys.piece_square_color[rook_dst][PieceType::Rook][color];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn drop_en_passant_hash(&mut self, en_passant: Option<usize>) {
|
|
|
|
|
|