Skip to content

Commit

Permalink
simplify implementation of PVS
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Sep 3, 2023
1 parent dbe1484 commit 9a60ce6
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions lib/search/pvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ impl Searcher {
.into_par_iter()
.rev()
.map(|&(m, guess)| {
use Ordering::Relaxed;
let mut alpha = Score::new(cutoff.load(Relaxed));
let alpha = Score::new(cutoff.load(Ordering::Relaxed));

if alpha >= beta {
return Ok(None);
Expand All @@ -260,21 +259,13 @@ impl Searcher {
}
}

loop {
match -self.nw(&next, -alpha, depth, ply + 1, timer)? {
pv if pv < alpha => return Ok(Some(pv.shift(m))),
pv => match Score::new(cutoff.fetch_max(pv.score().get(), Relaxed)) {
_ if pv >= beta => return Ok(Some(pv.shift(m))),
a if a >= beta => return Ok(None),
a if pv < a => alpha = a,
a => {
let pv = -self.pvs(&next, -beta..-a, depth, ply + 1, timer)?;
cutoff.fetch_max(pv.score().get(), Relaxed);
return Ok(Some(pv.shift(m)));
}
},
}
}
let pv = match -self.nw(&next, -alpha, depth, ply + 1, timer)? {
pv if pv < alpha => return Ok(Some(pv.shift(m))),
_ => -self.pvs(&next, -beta..-alpha, depth, ply + 1, timer)?,
};

cutoff.fetch_max(pv.score().get(), Ordering::Relaxed);
Ok(Some(pv.shift(m)))
})
.chain([Ok(Some(pv))])
.try_reduce(|| None, |a, b| Ok(max(a, b)))?
Expand Down

0 comments on commit 9a60ce6

Please sign in to comment.