Skip to content

Commit

Permalink
implement razoring
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Jan 20, 2025
1 parent 2a9a859 commit 18b3d9e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/search/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,25 @@ impl Engine {
}
}

/// An implementation of [razoring].
///
/// [razoring]: https://www.chessprogramming.org/Razoring
fn razor(&self, deficit: Score, draft: Depth) -> Option<Depth> {
match deficit.get() {
..0 => None,
s @ 0..600 => Some(draft - (s + 30) / 210),
600.. => Some(draft - 3),
}
}

/// An implementation of [reverse futility pruning].
///
/// [reverse futility pruning]: https://www.chessprogramming.org/Reverse_Futility_Pruning
fn rfp(&self, surplus: Score, draft: Depth) -> Option<Depth> {
match surplus.get() {
..0 => None,
s @ 0..440 => Some(draft - (s + 40) / 120),
440.. => Some(draft - 4),
s @ 0..360 => Some(draft - (s + 60) / 140),
360.. => Some(draft - 3),
}
}

Expand Down Expand Up @@ -229,6 +240,14 @@ impl Engine {
}
}

if let Some(d) = self.razor(alpha - upper, draft) {
if !is_pv && t.draft() >= d {
#[cfg(not(test))]
// The razoring heuristic is not exact.
return Ok(transposed.convert());
}
}

if let Some(d) = self.rfp(lower - beta, draft) {
if !is_pv && t.draft() >= d {
#[cfg(not(test))]
Expand Down

0 comments on commit 18b3d9e

Please sign in to comment.