Skip to content

Commit

Permalink
Wrap depth reductions in DepthReduction struct
Browse files Browse the repository at this point in the history
This lets us easily encapsulate the fact that the reduction should not
be less than zero, and give nice names to decreasing and increasing the
reduction.

Ran a few thousand games at STC with negligible Elo diff:

Elo   | 1.91 +- 8.72 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=16MB
LLR   | 0.61 (-2.94, 2.94) [-5.00, 0.00]
Games | N: 2732 W: 752 L: 737 D: 1243
Penta | [60, 346, 557, 325, 78]
  • Loading branch information
jgilchrist committed Nov 17, 2024
1 parent 02a7ca9 commit f773e9c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/engine/search/negamax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ use crate::engine::search::time_control::TimeStrategy;
use crate::engine::search::transposition::{NodeBound, SearchTranspositionTableData};
use crate::engine::tablebases::Wdl;

pub struct DepthReduction(u8);

impl DepthReduction {
#[inline]
#[expect(unused)]
pub fn increase_if(&mut self, predicate: bool) {
self.0 = self.0.saturating_add(predicate as u8);
}

#[inline]
#[expect(unused)]
pub fn reduce_if(&mut self, predicate: bool) {
self.0 = self.0.saturating_sub(predicate as u8);
}

#[inline]
pub fn value(&self) -> u8 {
self.0
}
}

pub fn negamax(
game: &mut Game,
mut alpha: Eval,
Expand Down Expand Up @@ -205,7 +226,8 @@ pub fn negamax(
&& number_of_legal_moves >= params::LMR_MOVE_THRESHOLD
&& !in_check
{
lmr_reduction(depth, number_of_legal_moves)
let reduction = DepthReduction(lmr_reduction(depth, number_of_legal_moves));
reduction.value()
} else {
1
};
Expand Down

0 comments on commit f773e9c

Please sign in to comment.