Skip to content

Commit e713e48

Browse files
committed
only update the killer if quiet pv causes cutoff
1 parent 0fa1f07 commit e713e48

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

lib/search/engine.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::chess::{Move, Zobrist};
21
use crate::nnue::{Evaluator, Value};
3-
use crate::search::*;
42
use crate::util::{Assume, Counter, Integer, Timer};
3+
use crate::{chess::Move, search::*};
54
use arrayvec::ArrayVec;
65
use derive_more::{Display, Error};
76
use rayon::{prelude::*, ThreadPool, ThreadPoolBuilder};
@@ -66,15 +65,20 @@ impl Engine {
6665
}
6766

6867
/// Records a `[Transposition`].
69-
fn record(&self, key: Zobrist, bounds: Range<Score>, depth: Depth, ply: Ply, pv: Pv) -> Pv {
68+
fn record(&self, pos: &Evaluator, bounds: Range<Score>, depth: Depth, ply: Ply, pv: Pv) -> Pv {
69+
let m = pv.best().assume();
70+
if pv >= bounds.end && m.is_quiet() {
71+
Self::KILLERS.with_borrow_mut(|ks| ks.insert(ply, pos.turn(), m));
72+
}
73+
7074
self.tt.set(
71-
key,
75+
pos.zobrist(),
7276
if pv.score() >= bounds.end {
73-
Transposition::lower(depth - ply, pv.score().normalize(-ply), pv.best().assume())
77+
Transposition::lower(depth - ply, pv.score().normalize(-ply), m)
7478
} else if pv.score() <= bounds.start {
75-
Transposition::upper(depth - ply, pv.score().normalize(-ply), pv.best().assume())
79+
Transposition::upper(depth - ply, pv.score().normalize(-ply), m)
7680
} else {
77-
Transposition::exact(depth - ply, pv.score().normalize(-ply), pv.best().assume())
81+
Transposition::exact(depth - ply, pv.score().normalize(-ply), m)
7882
},
7983
);
8084

@@ -246,18 +250,12 @@ impl Engine {
246250
Some((m, _)) => {
247251
let mut next = pos.clone();
248252
next.play(m);
249-
let pv = m >> -self.pvs(&next, -beta..-alpha, depth, ply + 1, ctrl)?;
250-
251-
if pv >= beta && m.is_quiet() {
252-
Self::KILLERS.with_borrow_mut(|ks| ks.insert(ply, pos.turn(), m));
253-
}
254-
255-
pv
253+
m >> -self.pvs(&next, -beta..-alpha, depth, ply + 1, ctrl)?
256254
}
257255
};
258256

259257
if pv >= beta {
260-
return Ok(self.record(pos.zobrist(), bounds, depth, ply, pv));
258+
return Ok(self.record(pos, bounds, depth, ply, pv));
261259
}
262260

263261
let cutoff = AtomicI16::new(pv.score().max(alpha).get());
@@ -290,10 +288,6 @@ impl Engine {
290288
_ => m >> -self.pvs(&next, -beta..-alpha, depth, ply + 1, ctrl)?,
291289
};
292290

293-
if pv >= beta && m.is_quiet() {
294-
Self::KILLERS.with_borrow_mut(|ks| ks.insert(ply, pos.turn(), m));
295-
}
296-
297291
if pv > alpha {
298292
cutoff.fetch_max(pv.score().get(), Ordering::Relaxed);
299293
}
@@ -304,7 +298,7 @@ impl Engine {
304298
.try_reduce(|| None, |a, b| Ok(max(a, b)))?
305299
.assume();
306300

307-
Ok(self.record(pos.zobrist(), bounds, depth, ply, pv))
301+
Ok(self.record(pos, bounds, depth, ply, pv))
308302
}
309303

310304
/// An implementation of [aspiration windows] with [iterative deepening].

0 commit comments

Comments
 (0)