Remove tt cutoffs, fix capture move sorting, refactor

This commit is contained in:
stefiosif
2024-11-30 00:04:53 +02:00
parent f5b7056347
commit 316f40e6e5
7 changed files with 74 additions and 99 deletions

View File

@@ -2,10 +2,23 @@ use crate::{
board::mailbox::Mailbox, evaluation::evaluation::material_score, movegen::r#move::Move,
};
pub const fn mvv_lva(mailbox: &Mailbox, mv: Move) -> i32 {
pub fn sort_moves(mut moves: Vec<Move>, mailbox: &Mailbox, tt_move: Option<Move>) -> Vec<Move> {
if let Some(tt_move) = tt_move {
if let Some(tt_move_index) = moves.iter().position(|&mv| mv == tt_move) {
moves.remove(tt_move_index);
moves.insert(0, tt_move);
return moves;
}
}
moves.sort_unstable_by_key(|mv| std::cmp::Reverse(mvv_lva(mailbox, *mv)));
moves
}
const fn mvv_lva(mailbox: &Mailbox, mv: Move) -> i32 {
match (mailbox.piece_at(mv.src), mailbox.piece_at(mv.dst)) {
(Some(aggressor), Some(victim)) => material_score(victim) - material_score(aggressor),
_ => 0,
_ => -1000,
}
}