Skip to content

Commit

Permalink
Index killers by ply
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes committed May 1, 2024
1 parent d576b7b commit 34a140b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/search/movepick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct MovePicker<const QUIESCE: bool> {
stage: MoveStage,
position: Position,
table: Option<Arc<SearchTable>>,
depth: Option<Depth>,
ply: Depth,
}

impl MovePicker<true> {
Expand All @@ -34,7 +34,7 @@ impl MovePicker<true> {
stage: MoveStage::CapturesAndPromotions,
position: *position,
table: None,
depth: None,
ply: 0,
}
}
}
Expand All @@ -48,7 +48,7 @@ impl std::iter::Iterator for MovePicker<true> {
}

impl MovePicker<false> {
pub fn new(position: &Position, table: Arc<SearchTable>, depth: Depth, shuffle: bool) -> Self {
pub fn new(position: &Position, table: Arc<SearchTable>, ply: Depth, shuffle: bool) -> Self {
let moves = if !shuffle {
if let Some(hash_move) = table.get_hash_move(position) {
vec![(hash_move, ValueScore::MAX)]
Expand All @@ -69,7 +69,7 @@ impl MovePicker<false> {
stage: if !shuffle { MoveStage::HashMove } else { MoveStage::All },
position: *position,
table: Some(table),
depth: Some(depth),
ply,
}
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ impl std::iter::Iterator for MovePicker<false> {
self.stage = MoveStage::NonCaptures;
let all_non_capture_moves = self.position.moves(MoveStage::NonCaptures);

let killers = self.table.as_ref().unwrap().get_killers(self.depth.unwrap());
let killers = self.table.as_ref().unwrap().get_killers(self.ply);
self.moves = decorate_moves_with_score(&all_non_capture_moves, |mov| {
if killers[1] == Some(mov) || killers[0] == Some(mov) {
Piece::Queen.value()
Expand Down
4 changes: 2 additions & 2 deletions src/search/pvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn pvs<const ROOT: bool, const MAIN_THREAD: bool, const ALLOW_NMR: bool>(

// Prepare move generation and sorting. This is lazy and works in stages.
let mut picker =
MovePicker::<false>::new(position, table.clone(), depth, ROOT && !MAIN_THREAD).peekable();
MovePicker::<false>::new(position, table.clone(), ply, ROOT && !MAIN_THREAD).peekable();

// Detect checkmate and stalemate
if picker.peek().is_none() {
Expand Down Expand Up @@ -314,7 +314,7 @@ fn pvs<const ROOT: bool, const MAIN_THREAD: bool, const ALLOW_NMR: bool>(
if MAIN_THREAD && mov.flag().is_quiet() {
// Killer moves are prioritized in move ordering.
// It assumes that similar "refutation" moves at siblings will be useful.
table.put_killer_move(depth, mov);
table.put_killer_move(ply, mov);
}

// This position is now far too good to be true.
Expand Down
10 changes: 5 additions & 5 deletions src/search/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl TranspositionTable {

pub struct SearchTable {
transposition: RwLock<TranspositionTable>,
killer_moves: [AtomicU16; 2 * (MAX_DEPTH + 1) as usize],
killer_moves: [AtomicU16; 3 * (MAX_DEPTH + 1) as usize],
}

impl SearchTable {
Expand Down Expand Up @@ -255,8 +255,8 @@ impl SearchTable {
}
}

pub fn put_killer_move(&self, depth: Depth, mov: Move) {
let index = 2 * depth as usize;
pub fn put_killer_move(&self, ply: Depth, mov: Move) {
let index = 2 * ply as usize;
if self.load_killer(index).is_none() {
self.store_killer(index, mov);
} else if self.load_killer(index + 1).is_none() {
Expand All @@ -270,8 +270,8 @@ impl SearchTable {
}
}

pub fn get_killers(&self, depth: Depth) -> [Option<Move>; 2] {
let index = 2 * depth as usize;
pub fn get_killers(&self, ply: Depth) -> [Option<Move>; 2] {
let index = 2 * ply as usize;
[self.load_killer(index), self.load_killer(index + 1)]
}

Expand Down

0 comments on commit 34a140b

Please sign in to comment.