Add depth limit on quiescence, add node/timer measurements

This commit is contained in:
stefiosif
2024-10-16 21:36:48 +03:00
parent b2df931d48
commit ff6bbafc50
6 changed files with 64 additions and 25 deletions

View File

@@ -9,6 +9,8 @@ use crate::{
use super::{move_ordering::score_by_mvv_lva, quiescence::quiescence};
const QUIESCENCE_DEPTH: u8 = 3;
pub fn negamax(
game: &mut Game,
mut alpha: i32,
@@ -16,9 +18,13 @@ pub fn negamax(
depth: u8,
plies: u8,
tt: &mut TranspositionTable,
nodes: &mut u64,
) -> (Option<Move>, i32) {
*nodes += 1;
if depth == 0 {
return (None, quiescence(game, alpha, beta).1);
let q = quiescence(game, alpha, beta, nodes, QUIESCENCE_DEPTH).1;
return (None, q);
}
if let Some(entry) = tt.lookup(game.hash) {
@@ -44,9 +50,9 @@ pub fn negamax(
game.unmake_move();
continue;
}
legal_moves += 1;
let move_score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, tt).1;
legal_moves += 1;
let move_score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, tt, nodes).1;
game.unmake_move();
if move_score > best_score {
@@ -117,9 +123,11 @@ mod tests {
let mut tt = TranspositionTable::new(1000000);
let e3f2 = Move::new(Square::E3, Square::F2);
let anointed_move = negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &mut tt)
let mut nodes = 0;
let anointed_move = negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &mut tt, &mut nodes)
.0
.unwrap();
dbg!(nodes);
assert_eq!(e3f2, anointed_move);