Pass Mailbox instead of Game on related functions for clarity

This commit is contained in:
stefiosif
2024-09-21 15:42:41 +03:00
parent 1ed4a0c2f9
commit a96d3d27b1
6 changed files with 25 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
use crate::{board::game::Game, movegen::r#move::Move};
use crate::{board::mailbox::Mailbox, movegen::r#move::Move};
// Rows: Aggressors (P, N, B, R, Q, K)
// Columns: Victims (K, Q, R, B, N, P)
@@ -12,11 +12,8 @@ const MVV_LVA: [[usize; 6]; 6] = [
[5, 4, 3, 2, 1, 0],
];
pub fn score_by_mvv_lva(game: &Game, mv: Move) -> usize {
match (
game.mailbox.find_piece_at(mv.src),
game.mailbox.find_piece_at(mv.dst),
) {
pub const fn score_by_mvv_lva(mailbox: &Mailbox, mv: Move) -> usize {
match (mailbox.find_piece_at(mv.src), mailbox.find_piece_at(mv.dst)) {
(Some(aggressor), Some(victim)) => MVV_LVA[aggressor.idx()][victim.idx()],
_ => 0,
}
@@ -36,7 +33,7 @@ mod tests {
fn test_score_by_mvv_lva() -> Result<(), String> {
let game = from_fen(FEN)?;
let f3f5 = Move::new_with_type(Square::F3, Square::F5, MoveType::Capture);
let actual = score_by_mvv_lva(&game, f3f5);
let actual = score_by_mvv_lva(&game.mailbox, f3f5);
let expected = MVV_LVA[PieceType::Queen.idx()][PieceType::Pawn.idx()];
assert_eq!(expected, actual);

View File

@@ -23,7 +23,7 @@ pub fn negamax(
let mut legal_moves = 0;
let mut pseudo_legal_moves = game.board.pseudo_moves_all();
pseudo_legal_moves.sort_unstable_by_key(|mv| score_by_mvv_lva(&game, *mv));
pseudo_legal_moves.sort_unstable_by_key(|mv| score_by_mvv_lva(&game.mailbox, *mv));
for mv in pseudo_legal_moves {
game.make_move(&mv);

View File

@@ -30,7 +30,7 @@ pub fn quiescence(game: &mut Game, mut alpha: i32, beta: i32) -> (Option<Move>,
})
.collect();
captures.sort_unstable_by_key(|mv| score_by_mvv_lva(&game, *mv));
captures.sort_unstable_by_key(|mv| score_by_mvv_lva(&game.mailbox, *mv));
for mv in captures {
game.make_move(&mv);