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 material corrhist. #208

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
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
43 changes: 8 additions & 35 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ pub struct Board {
minor_key: u64,
/// The Zobrist hash of the major pieces on the board.
major_key: u64,
/// The Zobrist hash of the counts of pieces on the board.
material_key: u64,

/// Squares that the opponent attacks
threats: Threats,
Expand Down Expand Up @@ -101,7 +99,6 @@ impl Board {
non_pawn_key: [0; 2],
minor_key: 0,
major_key: 0,
material_key: 0,
threats: Threats::default(),
castle_perm: CastlingRights::NONE,
history: Vec::new(),
Expand Down Expand Up @@ -154,13 +151,9 @@ impl Board {
self.major_key
}

pub const fn material_key(&self) -> u64 {
self.material_key
}

#[cfg(debug_assertions)]
pub const fn all_keys(&self) -> (u64, u64, [u64; 2], u64, u64, u64) {
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key, self.material_key)
pub const fn all_keys(&self) -> (u64, u64, [u64; 2], u64, u64) {
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key)
}

pub fn n_men(&self) -> u8 {
Expand Down Expand Up @@ -214,13 +207,12 @@ impl Board {
&mut self.castle_perm
}

pub fn generate_pos_keys(&self) -> (u64, u64, [u64; 2], u64, u64, u64) {
pub fn generate_pos_keys(&self) -> (u64, u64, [u64; 2], u64, u64) {
let mut key = 0;
let mut pawn_key = 0;
let mut non_pawn_key = [0; 2];
let mut minor_key = 0;
let mut major_key = 0;
let mut material_key = 0;
self.pieces.visit_pieces(|sq, piece| {
hash_piece(&mut key, piece, sq);
if piece.piece_type() == PieceType::Pawn {
Expand All @@ -238,14 +230,6 @@ impl Board {
}
});

for piece in Piece::all() {
// brutal disregard for type-based interfaces.
// (we're just re-using the PSQT hashkey table,
// but for a count rather than a square)
#[allow(clippy::cast_possible_truncation)]
hash_piece(&mut material_key, piece, Square::new_clamped(self.pieces.piece_bb(piece).count() as u8));
}

if self.side == Colour::White {
hash_side(&mut key);
}
Expand All @@ -258,12 +242,12 @@ impl Board {

debug_assert!(self.fifty_move_counter <= 100);

(key, pawn_key, non_pawn_key, minor_key, major_key, material_key)
(key, pawn_key, non_pawn_key, minor_key, major_key)
}

#[cfg(feature = "datagen")]
pub fn regenerate_zobrist(&mut self) {
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key, self.material_key) =
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key) =
self.generate_pos_keys();
}

Expand Down Expand Up @@ -375,7 +359,7 @@ impl Board {
bk: Some(Square::from_rank_file(Rank::Eight, File::from_index(kingside_file as u8).unwrap())),
bq: Some(Square::from_rank_file(Rank::Eight, File::from_index(queenside_file as u8).unwrap())),
};
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key, self.material_key) =
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key) =
self.generate_pos_keys();
self.threats = self.generate_threats(self.side.flip());
}
Expand Down Expand Up @@ -434,7 +418,7 @@ impl Board {
bk: Some(Square::from_rank_file(Rank::Eight, File::from_index(black_kingside_file as u8).unwrap())),
bq: Some(Square::from_rank_file(Rank::Eight, File::from_index(black_queenside_file as u8).unwrap())),
};
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key, self.material_key) =
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key) =
self.generate_pos_keys();
self.threats = self.generate_threats(self.side.flip());
}
Expand Down Expand Up @@ -577,7 +561,7 @@ impl Board {
self.set_halfmove(info_parts.next())?;
self.set_fullmove(info_parts.next())?;

(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key, self.material_key) =
(self.key, self.pawn_key, self.non_pawn_key, self.minor_key, self.major_key) =
self.generate_pos_keys();
self.threats = self.generate_threats(self.side.flip());

Expand Down Expand Up @@ -1052,7 +1036,6 @@ impl Board {
non_pawn_key: self.non_pawn_key,
minor_key: self.minor_key,
major_key: self.major_key,
material_key: self.material_key,
};

// from, to, and piece are valid unless this is a castling move,
Expand Down Expand Up @@ -1256,14 +1239,6 @@ impl Board {
self.non_pawn_key = non_pawn_key;
self.minor_key = minor_key;
self.major_key = major_key;
self.material_key = 0;
for piece in Piece::all() {
// brutal disregard for type-based interfaces.
// (we're just re-using the PSQT hashkey table,
// but for a count rather than a square)
#[allow(clippy::cast_possible_truncation)]
hash_piece(&mut self.material_key, piece, Square::new_clamped(self.pieces.piece_bb(piece).count() as u8));
}

self.ply += 1;
self.height += 1;
Expand Down Expand Up @@ -1301,7 +1276,6 @@ impl Board {
non_pawn_key,
minor_key,
major_key,
material_key,
..
} = undo;

Expand All @@ -1313,7 +1287,6 @@ impl Board {
self.non_pawn_key = *non_pawn_key;
self.minor_key = *minor_key;
self.major_key = *major_key;
self.material_key = *material_key;
self.castle_perm = *castle_perm;
self.ep_sq = *ep_square;
self.fifty_move_counter = *fifty_move_counter;
Expand Down
4 changes: 1 addition & 3 deletions src/board/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ impl ThreadData<'_> {
update(self.nonpawn_corrhist[Black].get_mut(us, pos.non_pawn_key(Black)), new_weight, scaled_diff);
update(self.minor_corrhist.get_mut(us, pos.minor_key()), new_weight, scaled_diff);
update(self.major_corrhist.get_mut(us, pos.major_key()), new_weight, scaled_diff);
update(self.material_corrhist.get_mut(us, pos.material_key()), new_weight, scaled_diff);
}

/// Adjust a raw evaluation using statistics from the correction history.
Expand All @@ -243,8 +242,7 @@ impl ThreadData<'_> {
let black = self.nonpawn_corrhist[Colour::Black].get(pos.turn(), pos.non_pawn_key(Colour::Black));
let minor = self.minor_corrhist.get(pos.turn(), pos.minor_key());
let major = self.major_corrhist.get(pos.turn(), pos.major_key());
let material = self.material_corrhist.get(pos.turn(), pos.material_key());
let adjustment = pawn + material + major + minor + white + black;
let adjustment = pawn + major + minor + white + black;
raw_eval + adjustment as i32 / CORRECTION_HISTORY_GRAIN
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/threadlocal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub struct ThreadData<'a> {
pub nonpawn_corrhist: [Box<CorrectionHistoryTable>; 2],
pub major_corrhist: Box<CorrectionHistoryTable>,
pub minor_corrhist: Box<CorrectionHistoryTable>,
pub material_corrhist: Box<CorrectionHistoryTable>,

pub thread_id: usize,

Expand Down Expand Up @@ -65,7 +64,6 @@ impl<'a> ThreadData<'a> {
nonpawn_corrhist: [CorrectionHistoryTable::boxed(), CorrectionHistoryTable::boxed()],
major_corrhist: CorrectionHistoryTable::boxed(),
minor_corrhist: CorrectionHistoryTable::boxed(),
material_corrhist: CorrectionHistoryTable::boxed(),
thread_id,
pvs: Self::EMPTY_PV_TABLE,
completed: 0,
Expand Down Expand Up @@ -100,7 +98,6 @@ impl<'a> ThreadData<'a> {
self.nonpawn_corrhist[Colour::Black].clear();
self.major_corrhist.clear();
self.minor_corrhist.clear();
self.material_corrhist.clear();
self.killer_move_table.fill([None; 2]);
self.counter_move_table.clear();
self.depth = 0;
Expand Down
3 changes: 0 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,6 @@ pub struct Undo {
pub minor_key: u64,
/// The Zobrist hash of the major pieces on the board.
pub major_key: u64,
/// The Zobrist hash of the counts of pieces on the board.
pub material_key: u64,
}

impl Default for Undo {
Expand All @@ -412,7 +410,6 @@ impl Default for Undo {
non_pawn_key: [0; 2],
minor_key: 0,
major_key: 0,
material_key: 0,
}
}
}
Expand Down
Loading