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

@@ -8,7 +8,7 @@ use crate::{
use super::{
move_ordering::score_move,
quiescence::quiescence,
time::{hard_limit, TimeInfo},
time::TimeInfo,
transposition_table::TTEntry,
};
@@ -18,11 +18,11 @@ pub fn negamax(
beta: i32,
depth: u8,
plies: u8,
time_info: &TimeInfo,
time: &TimeInfo,
nodes: &mut u64,
) -> Result<i32> {
if hard_limit(time_info.instant, time_info.time, time_info.inc) {
bail!("Time is up! In Negamax");
if time.exceed_hard_limit() {
bail!("Hard limit exceeded in negamax");
}
if plies != 0 && game.in_repetition() {
@@ -31,7 +31,7 @@ pub fn negamax(
if depth == 0 {
let q_score =
quiescence(game, alpha, beta, time_info, nodes).map_err(|e| anyhow!("{e}"))?;
quiescence(game, alpha, beta, time, nodes).map_err(|e| anyhow!("{e}"))?;
return Ok(q_score);
}
@@ -55,7 +55,7 @@ pub fn negamax(
*nodes += 1;
let score = if legal_moves == 1 {
-negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info, nodes)?
-negamax(game, -beta, -alpha, depth - 1, plies + 1, time, nodes)?
} else {
let mut score = -negamax(
game,
@@ -63,11 +63,11 @@ pub fn negamax(
-alpha,
depth - 1,
plies + 1,
time_info,
time,
nodes,
)?;
if score > alpha && score < beta {
score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info, nodes)?;
score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time, nodes)?;
}
score
};