Make mvv_lva to map pieces to their material score instead of abritrary matrix
Add time limits, use anyhow crate to improve error handling, remove depth limit on quiescence search
This commit is contained in:
@@ -1,20 +1,10 @@
|
||||
use crate::{board::mailbox::Mailbox, movegen::r#move::Move};
|
||||
use crate::{
|
||||
board::mailbox::Mailbox, evaluation::evaluation::material_score, movegen::r#move::Move,
|
||||
};
|
||||
|
||||
// Rows: Aggressors (P, N, B, R, Q, K)
|
||||
// Columns: Victims (K, Q, R, B, N, P)
|
||||
#[rustfmt::skip]
|
||||
const MVV_LVA: [[usize; 6]; 6] = [
|
||||
[30, 29, 28, 27, 26, 0],
|
||||
[25, 24, 23, 22, 21, 0],
|
||||
[20, 19, 18, 17, 16, 0],
|
||||
[15, 14, 13, 12, 11, 0],
|
||||
[10, 9, 8, 7, 6, 0],
|
||||
[5, 4, 3, 2, 1, 0],
|
||||
];
|
||||
|
||||
pub const fn score_by_mvv_lva(mailbox: &Mailbox, mv: Move) -> usize {
|
||||
pub const fn mvv_lva(mailbox: &Mailbox, mv: Move) -> i32 {
|
||||
match (mailbox.piece_at(mv.src), mailbox.piece_at(mv.dst)) {
|
||||
(Some(aggressor), Some(victim)) => MVV_LVA[aggressor.idx()][victim.idx()],
|
||||
(Some(aggressor), Some(victim)) => material_score(victim) - material_score(aggressor),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
@@ -22,9 +12,9 @@ pub const fn score_by_mvv_lva(mailbox: &Mailbox, mv: Move) -> usize {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
board::{board::PieceType, fen::from_fen, square::Square},
|
||||
board::{fen::from_fen, square::Square},
|
||||
movegen::r#move::{Move, MoveType},
|
||||
search::move_ordering::{score_by_mvv_lva, MVV_LVA},
|
||||
search::move_ordering::mvv_lva,
|
||||
};
|
||||
|
||||
const FEN: &'static str = "1r2k2r/2P1pq1p/2npb3/1p3ppP/p3P3/P2B1Q2/1P1PNPP1/R3K2R w KQk g6 0 1";
|
||||
@@ -33,10 +23,8 @@ mod tests {
|
||||
fn test_score_by_mvv_lva() -> Result<(), String> {
|
||||
let game = from_fen(FEN)?;
|
||||
let f3f5 = Move::with_type(Square::F3, Square::F5, MoveType::Capture);
|
||||
let actual = score_by_mvv_lva(&game.mailbox, f3f5);
|
||||
let expected = MVV_LVA[PieceType::Queen.idx()][PieceType::Pawn.idx()];
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(mvv_lva(&game.mailbox, f3f5), -800);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user