Add depth based logging
This commit is contained in:
@@ -19,6 +19,7 @@ pub fn negamax(
|
||||
depth: u8,
|
||||
plies: u8,
|
||||
time_info: &TimeInfo,
|
||||
total_nodes_searched: &mut u64,
|
||||
) -> Result<i32> {
|
||||
if hard_limit(&time_info.time, time_info.remaining_time_in_ms) {
|
||||
bail!("Time is up! In Negamax");
|
||||
@@ -29,7 +30,8 @@ pub fn negamax(
|
||||
}
|
||||
|
||||
if depth == 0 {
|
||||
let q_score = quiescence(game, alpha, beta, time_info).map_err(|e| anyhow!("{e}"))?;
|
||||
let q_score = quiescence(game, alpha, beta, time_info, total_nodes_searched)
|
||||
.map_err(|e| anyhow!("{e}"))?;
|
||||
return Ok(q_score);
|
||||
}
|
||||
|
||||
@@ -49,15 +51,39 @@ pub fn negamax(
|
||||
game.unmake_move();
|
||||
continue;
|
||||
}
|
||||
|
||||
legal_moves += 1;
|
||||
*total_nodes_searched += 1;
|
||||
|
||||
let score = if legal_moves == 1 {
|
||||
-negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info)?
|
||||
-negamax(
|
||||
game,
|
||||
-beta,
|
||||
-alpha,
|
||||
depth - 1,
|
||||
plies + 1,
|
||||
time_info,
|
||||
total_nodes_searched,
|
||||
)?
|
||||
} else {
|
||||
let mut score = -negamax(game, -alpha - 1, -alpha, depth - 1, plies + 1, time_info)?;
|
||||
let mut score = -negamax(
|
||||
game,
|
||||
-alpha - 1,
|
||||
-alpha,
|
||||
depth - 1,
|
||||
plies + 1,
|
||||
time_info,
|
||||
total_nodes_searched,
|
||||
)?;
|
||||
if score > alpha && score < beta {
|
||||
score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info)?;
|
||||
score = -negamax(
|
||||
game,
|
||||
-beta,
|
||||
-alpha,
|
||||
depth - 1,
|
||||
plies + 1,
|
||||
time_info,
|
||||
total_nodes_searched,
|
||||
)?;
|
||||
}
|
||||
score
|
||||
};
|
||||
@@ -110,7 +136,7 @@ mod tests {
|
||||
|
||||
let e3f2 = Move::new(Square::E3, Square::F2);
|
||||
let time_info = TimeInfo::new(std::time::Instant::now(), 1000);
|
||||
negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info)
|
||||
negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info, &mut 0)
|
||||
.expect("Expected a search result");
|
||||
|
||||
assert_eq!(e3f2, game.tt.lookup(game.hash).unwrap().mv.unwrap());
|
||||
@@ -118,7 +144,7 @@ mod tests {
|
||||
let mut game = from_fen(FEN_MATE_IN_1[1]).unwrap();
|
||||
|
||||
let e3f2 = Move::new(Square::E3, Square::F2);
|
||||
negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info)
|
||||
negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info, &mut 0)
|
||||
.expect("Expected a search result");
|
||||
|
||||
assert_eq!(e3f2, game.tt.lookup(game.hash).unwrap().mv.unwrap());
|
||||
|
||||
Reference in New Issue
Block a user