Refactor time info, update zobrist to tuple struct, naming and clippy

This commit is contained in:
stefiosif
2025-01-26 20:16:01 +02:00
parent 36aa30ea17
commit 53beda7fe3
11 changed files with 78 additions and 77 deletions

View File

@@ -9,25 +9,26 @@ use crate::{
use super::{
negamax,
time::{hard_limit, TimeInfo},
time::TimeInfo,
};
pub fn iterative_deepening(
game: &mut Game,
max_depth: u8,
time_info: &TimeInfo,
time: &TimeInfo,
) -> anyhow::Result<Option<Move>> {
let mut best_move = None;
for depth in 1..=max_depth {
if hard_limit(time_info.instant, time_info.time, time_info.inc) {
if time.exceed_hard_limit() {
return Ok(best_move);
}
let mut nodes = 0;
let score = negamax::negamax(game, MIN_SCORE, MAX_SCORE, depth, 0, time_info, &mut nodes);
let score = negamax::negamax(game, MIN_SCORE, MAX_SCORE, depth, 0, time, &mut nodes);
if score.is_err() {
if let Err(e) = score {
write_response(&mut io::stdout(), &Response::Info(format!("{e}")))?;
break;
}
@@ -37,9 +38,9 @@ pub fn iterative_deepening(
&mut io::stdout(),
&log_depth_results(
depth,
time_info.instant.elapsed().as_millis() as u64,
time.instant.elapsed().as_millis() as u64,
nodes,
time_info.nps(nodes),
time.nps(nodes),
score?,
best_move,
),