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,43 +2,47 @@ use anyhow::{bail, Result};
use crate::{board::game::Game, evaluation::evaluation::evaluate_position};
use super::{iterative_deepening::hard_limit, move_ordering::mvv_lva, time::TimeInfo};
use super::{
move_ordering,
time::{hard_limit, TimeInfo},
};
pub fn quiescence(game: &mut Game, mut alpha: i32, beta: i32, time_info: &TimeInfo) -> Result<i32> {
if hard_limit(&time_info.time, time_info.remaining_time_in_ms) {
bail!("Time is up! In Quiescence");
}
let color = game.current_player();
let stand_pat = evaluate_position(&game.board);
if stand_pat >= beta {
return Ok(beta);
}
if alpha < stand_pat {
if stand_pat > alpha {
alpha = stand_pat;
}
let mut captures: Vec<_> = game.board.pseudo_moves_all_captures();
captures.sort_unstable_by_key(|mv| mvv_lva(&game.mailbox, *mv));
let color = game.current_player();
let all_moves = game.board.pseudo_moves_all_captures();
let moves = move_ordering::sort_moves(all_moves, &game.mailbox, None);
for mv in captures {
for mv in moves {
game.make_move(&mv);
if game.board.king_under_check(color) {
game.unmake_move();
continue;
}
let move_score = -quiescence(game, -beta, -alpha, time_info)?;
let score = -quiescence(game, -beta, -alpha, time_info)?;
game.unmake_move();
if move_score >= beta {
if score >= beta {
return Ok(beta);
}
if alpha > move_score {
alpha = move_score
if score > alpha {
alpha = score
}
}