Skip to content

Commit

Permalink
refactor: removed branch from mate score adjustment code & put it int…
Browse files Browse the repository at this point in the history
…o it's own function

bench: 8515103
  • Loading branch information
dannyhammer committed Jan 4, 2025
1 parent c82b043 commit 3f182b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ impl Score {
Self(self.0.abs())
}

/// Returns the sign of this [`Score`].
/// If this [`Score`] is a mate score, adjust it by 1 to propagate up the search tree.
///
/// This helps with mate score adjustments, ensuring that a mate score is always relative to the current ply.
#[inline(always)]
pub const fn signum(self) -> Self {
Self(self.0.signum())
pub const fn adjust_mate(&mut self) {
self.0 -= self.0.signum() * self.is_mate() as i32
}

/// "Normalizes" a score so that it can be printed as a float.
Expand Down
8 changes: 2 additions & 6 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,7 @@ impl<'a, Log: LogLevel, V: Variant> Search<'a, Log, V> {
}

// Adjust mate score by 1 ply, since we're returning up the call stack
if best.is_mate() {
best -= best.signum();
}
best.adjust_mate();

// Save this node to the TTable.
self.save_to_tt(
Expand Down Expand Up @@ -1225,9 +1223,7 @@ impl<'a, Log: LogLevel, V: Variant> Search<'a, Log, V> {
}

// Adjust mate score by 1 ply, since we're returning up the call stack
if best.is_mate() {
best -= best.signum();
}
best.adjust_mate();

// Save this node to the TTable.
self.save_to_tt(
Expand Down

0 comments on commit 3f182b8

Please sign in to comment.