Skip to content

Commit

Permalink
Perform lazy SEE to separate captures
Browse files Browse the repository at this point in the history
Not sure if bench is supposed to change...

bench 6379520
  • Loading branch information
sroelants committed Sep 28, 2024
1 parent 23e35a8 commit dcdfaeb
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions simbelmyne/src/move_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,23 @@ impl<'pos> MovePicker<'pos> {
return Some(best_move);
}

fn is_good_tactical(&self, mv: Move) -> bool {
use PieceType::*;
if mv.is_capture() {
self.position.board.see(mv, 0)
} else {
mv.get_promo_type().is_some_and(|pt| pt == Queen)
}
}

/// Score captures according to MVV-LVA (Most Valuable Victim, Least
/// Valuable Attacker)
fn score_tacticals(&mut self, history: &History) {
use PieceType::*;
let mut i = self.index;

while i < self.bad_tactical_index {
while i < self.moves.len() {
let mv = self.moves[i];

let is_bad_tactical = if mv.is_capture() {
!self.position.board.see(mv, 0)
} else {
mv.get_promo_type().is_some_and(|pt| pt != Queen)
};

////////////////////////////////////////////////////////////////////
//
// Score captures according to MVV + Capthist
Expand Down Expand Up @@ -231,15 +233,15 @@ impl<'pos> MovePicker<'pos> {
//
////////////////////////////////////////////////////////////////////

if is_bad_tactical {
self.bad_tactical_index -= 1;
self.swap_moves(i, self.bad_tactical_index);

// Important that we don't increment the counter just yet, but
// process the i'th position again, since we don't know what
// move we just put there.
continue;
}
// if self.is_bad_tactical(mv) {
// self.bad_tactical_index -= 1;
// self.swap_moves(i, self.bad_tactical_index);
//
// // Important that we don't increment the counter just yet, but
// // process the i'th position again, since we don't know what
// // move we just put there.
// continue;
// }

i += 1;
}
Expand Down Expand Up @@ -357,12 +359,19 @@ impl<'a> MovePicker<'a> {
// partial sort on every run, so we do progressively less work on these
// scans
if self.stage == Stage::GoodTacticals {
if self.index < self.bad_tactical_index {
while self.index < self.bad_tactical_index {
let tactical = self.partial_sort(self.index, self.bad_tactical_index);

self.index += 1;
return tactical;
} else if self.only_good_tacticals {
if self.is_good_tactical(tactical.unwrap()) {
self.index += 1;
return tactical;
} else {
self.bad_tactical_index -= 1;
self.swap_moves(self.index, self.bad_tactical_index);
}
}

if self.only_good_tacticals {
self.stage = Stage::Done
} else {
self.stage = Stage::GenerateQuiets;
Expand All @@ -374,7 +383,7 @@ impl<'a> MovePicker<'a> {
// Generate quiets
//
////////////////////////////////////////////////////////////////////////

if self.stage == Stage::GenerateQuiets {
if self.position.board.current.is_white() {
self.position.board.legal_moves_for::<WHITE, Quiets>(&mut self.moves);
Expand Down

0 comments on commit dcdfaeb

Please sign in to comment.