Use increment from uci winc/binc in time management
This commit is contained in:
@@ -19,9 +19,9 @@ pub fn negamax(
|
||||
depth: u8,
|
||||
plies: u8,
|
||||
time_info: &TimeInfo,
|
||||
total_nodes_searched: &mut u64,
|
||||
nodes: &mut u64,
|
||||
) -> Result<i32> {
|
||||
if hard_limit(&time_info.time, time_info.remaining_time_in_ms) {
|
||||
if hard_limit(time_info.instant, time_info.time, time_info.inc) {
|
||||
bail!("Time is up! In Negamax");
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ pub fn negamax(
|
||||
}
|
||||
|
||||
if depth == 0 {
|
||||
let q_score = quiescence(game, alpha, beta, time_info, total_nodes_searched)
|
||||
.map_err(|e| anyhow!("{e}"))?;
|
||||
let q_score =
|
||||
quiescence(game, alpha, beta, time_info, nodes).map_err(|e| anyhow!("{e}"))?;
|
||||
return Ok(q_score);
|
||||
}
|
||||
|
||||
@@ -52,18 +52,10 @@ pub fn negamax(
|
||||
continue;
|
||||
}
|
||||
legal_moves += 1;
|
||||
*total_nodes_searched += 1;
|
||||
*nodes += 1;
|
||||
|
||||
let score = if legal_moves == 1 {
|
||||
-negamax(
|
||||
game,
|
||||
-beta,
|
||||
-alpha,
|
||||
depth - 1,
|
||||
plies + 1,
|
||||
time_info,
|
||||
total_nodes_searched,
|
||||
)?
|
||||
-negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info, nodes)?
|
||||
} else {
|
||||
let mut score = -negamax(
|
||||
game,
|
||||
@@ -72,18 +64,10 @@ pub fn negamax(
|
||||
depth - 1,
|
||||
plies + 1,
|
||||
time_info,
|
||||
total_nodes_searched,
|
||||
nodes,
|
||||
)?;
|
||||
if score > alpha && score < beta {
|
||||
score = -negamax(
|
||||
game,
|
||||
-beta,
|
||||
-alpha,
|
||||
depth - 1,
|
||||
plies + 1,
|
||||
time_info,
|
||||
total_nodes_searched,
|
||||
)?;
|
||||
score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info, nodes)?;
|
||||
}
|
||||
score
|
||||
};
|
||||
@@ -123,6 +107,7 @@ mod tests {
|
||||
use crate::movegen::r#move::Move;
|
||||
use crate::search::negamax::negamax;
|
||||
use crate::search::time::TimeInfo;
|
||||
use crate::search::{INC, TIME};
|
||||
|
||||
const FEN_MATE_IN_1: [&str; 2] = [
|
||||
"8/8/8/8/8/4q1k1/8/5K2 b - - 0 1",
|
||||
@@ -135,7 +120,7 @@ mod tests {
|
||||
let mut game = from_fen(FEN_MATE_IN_1[0]).unwrap();
|
||||
|
||||
let e3f2 = Move::new(Square::E3, Square::F2);
|
||||
let time_info = TimeInfo::new(std::time::Instant::now(), 1000);
|
||||
let time_info = TimeInfo::new(std::time::Instant::now(), TIME, INC);
|
||||
negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info, &mut 0)
|
||||
.expect("Expected a search result");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user