Skip to content

Commit

Permalink
tweak move ordering
Browse files Browse the repository at this point in the history
Rank Name                          Elo     +/-   Games    Wins  Losses   Draws   Points   Score    Draw
   0 dev                             7       6    9000    3062    2879    3059   4591.5   51.0%   34.0%
   1 Nalwald-18                     18      10    3000    1041     890    1069   1575.5   52.5%   35.6%
   2 Counter-5.0                     8      10    3000    1087    1016     897   1535.5   51.2%   29.9%
   3 StockNemo-5.7                 -47      10    3000     751    1156    1093   1297.5   43.3%   36.4%
  • Loading branch information
brunocodutra committed Jan 18, 2024
1 parent a0d677e commit 616e30b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
2 changes: 0 additions & 2 deletions lib/nnue/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ impl<T: Clone + Accumulator> Evaluator<T> {
/// Exchange a piece on [`Square`] by the attacker of least value.
///
/// This may lead to invalid positions.
#[inline(always)]
fn exchange(&mut self, whither: Square) -> Result<Move, ImpossibleExchange> {
let capture = self.role_on(whither);
let m = self.pos.exchange(whither)?;
Expand All @@ -114,7 +113,6 @@ impl<T: Clone + Accumulator> Evaluator<T> {
Ok(m)
}

#[inline(always)]
fn update(&mut self, m: Move, capture: Option<Role>) {
let turn = self.turn();

Expand Down
35 changes: 16 additions & 19 deletions lib/search/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ impl Engine {
_ => depth,
};

let alpha = match ply >= depth && !in_check {
let quiesce = ply >= depth && !in_check;
let alpha = match quiesce {
#[cfg(not(test))]
// The stand pat heuristic is not exact.
true => alpha.max(score),
Expand Down Expand Up @@ -231,27 +232,23 @@ impl Engine {
}

let mut moves = Buffer::<_, 256>::from_iter(pos.moves().filter_map(|m| {
if ply >= depth && !in_check && m.is_quiet() {
return None;
if quiesce && m.is_quiet() {
None
} else if Some(m) == tpos.map(|t| t.best()) {
return Some((m, Value::UPPER));
}

let mut next = pos.material();
let material = next.evaluate();
next.play(m);
let see = -next.see(m.whither());

let gain = if Self::KILLERS.with_borrow(|ks| ks.contains(ply, pos.turn(), m)) {
Value::new(100).max(see - material)
Some((m, Value::UPPER))
} else if Self::KILLERS.with_borrow(|ks| ks.contains(ply, pos.turn(), m)) {
Some((m, Value::new(100)))
} else if m.is_quiet() {
Some((m, Value::new(0)))
} else {
see - material
};

Some((m, gain))
let mut next = pos.material();
let material = next.evaluate();
next.play(m);
Some((m, -next.evaluate() - material))
}
}));

moves.sort_unstable_by_key(|(_, rank)| *rank);
moves.sort_unstable_by_key(|(_, gain)| *gain);

let best = match moves.pop() {
None => return Ok(Pv::new(score, [])),
Expand Down Expand Up @@ -289,7 +286,7 @@ impl Engine {
let mut next = pos.clone();
next.play(m);

if !in_check && gain < 60 {
if !in_check && gain < 100 {
let guess = -next.clone().see(m.whither()).cast();
if let Some(d) = self.lmp(&next, guess, alpha, depth, ply) {
if d <= ply || -self.nw(&next, -alpha, d, ply + 1, ctrl)? <= alpha {
Expand Down

0 comments on commit 616e30b

Please sign in to comment.