Add one killer move per ply

This commit is contained in:
stefiosif
2025-01-27 22:21:21 +02:00
parent b4f61f6504
commit ccba6451aa
6 changed files with 39 additions and 7 deletions

View File

@@ -1,10 +1,19 @@
use crate::{board::mailbox::Mailbox, movegen::r#move::Move};
pub fn score_move(mailbox: &Mailbox, mv: Move, tt_move: Option<Move>) -> i32 {
pub fn score_move(
mailbox: &Mailbox,
mv: Move,
killer_move: Option<Move>,
tt_move: Option<Move>,
) -> i32 {
if Some(mv) == tt_move {
return -100;
}
if Some(mv) == killer_move {
return -90;
}
let aggressor = mailbox.piece_at(mv.src).expect("No aggressor found.");
mailbox.piece_at(mv.dst).map_or(100, |victim| {
aggressor.0.idx() as i32 - (victim.0.idx() * 8) as i32
@@ -30,11 +39,11 @@ mod tests {
let castle = Move::with_type(Square::E1, Square::C1, MoveType::Castle);
let mut moves = vec![castle, queen_takes_pawn, pawn_takes_queen];
moves.sort_unstable_by_key(|mv| score_move(&game.mailbox, *mv, None));
moves.sort_unstable_by_key(|mv| score_move(&game.mailbox, *mv, None, None));
assert_eq!(moves, vec![pawn_takes_queen, queen_takes_pawn, castle]);
moves.sort_unstable_by_key(|mv| score_move(&game.mailbox, *mv, Some(castle)));
moves.sort_unstable_by_key(|mv| score_move(&game.mailbox, *mv, None, Some(castle)));
assert_eq!(moves, vec![castle, pawn_takes_queen, queen_takes_pawn]);