Skip to content

Commit

Permalink
implement reverse futility pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Nov 17, 2024
1 parent e1af234 commit 299af59
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/search/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ impl Engine {
(bounds.start.max(lower), bounds.end.min(upper))
}

/// An implementation of [reverse futility pruning].
///
/// [reverse futility pruning]: https://www.chessprogramming.org/Reverse_Futility_Pruning
fn rfp(&self, depth: Depth, ply: Ply) -> Score {
match (depth - ply).get() {
draft @ ..=6 => Score::new(100) * draft,
_ => Score::upper(),
}
}

/// An implementation of [null move pruning].
///
/// [null move pruning]: https://www.chessprogramming.org/Null_Move_Pruning
Expand Down Expand Up @@ -187,6 +197,10 @@ impl Engine {

if alpha >= beta || ply >= Ply::MAX {
return Ok(Pv::new(score, None));
} else if score - self.rfp(depth, ply) >= beta {
#[cfg(not(test))]
// The reverse futility pruning heuristic is not exact.
return Ok(Pv::new(score, None));
} else if !is_pv && !pos.is_check() && pos.pieces(pos.turn()).len() > 1 {
if let Some(d) = self.nmp(score, beta, depth, ply) {
let mut next = pos.clone();
Expand Down

0 comments on commit 299af59

Please sign in to comment.