Add depth based logging

This commit is contained in:
stefiosif
2025-01-25 21:47:11 +02:00
parent 2ed92f9253
commit 2d9076cd1d
6 changed files with 133 additions and 34 deletions

View File

@@ -1,6 +1,9 @@
use std::io;
use crate::{
board::game::Game,
evaluation::{MAX_SCORE, MIN_SCORE},
interface::uci::{write_response, Response},
movegen::r#move::Move,
};
@@ -22,6 +25,8 @@ pub fn iterative_deepening(
return Ok(best_move);
}
let mut total_nodes_searched = 0;
let score = negamax::negamax(
game,
MIN_SCORE,
@@ -29,6 +34,7 @@ pub fn iterative_deepening(
depth,
0,
&TimeInfo::new(time, remaining_time),
&mut total_nodes_searched,
);
if score.is_err() {
@@ -37,10 +43,44 @@ pub fn iterative_deepening(
best_score = score?;
best_move = game.tt.lookup(game.hash).and_then(|entry| entry.mv);
let nps = ((total_nodes_searched * 1_000_000) as u128).div_ceil(time.elapsed().as_micros())
as u64;
write_response(
&mut io::stdout(),
&search_info(
depth,
time.elapsed().as_millis() as u64,
total_nodes_searched,
nps,
best_score,
best_move,
),
)?;
}
Ok(best_move)
}
fn search_info(
depth: u8,
time: u64,
total_nodes_searched: u64,
nps: u64,
best_score: i32,
best_move: Option<Move>,
) -> Response {
Response::Info(format!(
"info depth {} time {} nodes {} nps {} eval {} pv {}",
depth,
time,
total_nodes_searched,
nps,
best_score,
best_move.expect("msg: No best move found")
))
}
#[cfg(test)]
mod tests {
use crate::{