diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-02-02 20:32:54 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-02-02 20:37:33 +0300 |
commit | ec05e8bfa3f61b86fb83d939ff6fa3ddbc51ce6d (patch) | |
tree | 0f7c62e1ca4d28d71843db3b0a411edc6926bf12 | |
parent | abb303329c9a1628c6f1e5d29fb1a48021a87879 (diff) | |
download | chessnost-ec05e8bfa3f61b86fb83d939ff6fa3ddbc51ce6d.tar.gz |
feat: remove logs when pondering
-rw-r--r-- | benches/search.rs | 2 | ||||
-rw-r--r-- | src/board/engine.rs | 28 | ||||
-rw-r--r-- | src/main.rs | 14 |
3 files changed, 26 insertions, 18 deletions
diff --git a/benches/search.rs b/benches/search.rs index 41027f9..797638e 100644 --- a/benches/search.rs +++ b/benches/search.rs @@ -6,7 +6,7 @@ fn main() { let mut board = Board::from_FEN(fen); let start = Instant::now(); - let (score, pv) = board.iterative_deepening(6, Duration::from_secs(15)); + let (score, pv) = board.iterative_deepening(6, Duration::from_secs(15), true); println!("Finished in {:?}: score={:?} {:?}", start.elapsed(), score, pv); board.print(); diff --git a/src/board/engine.rs b/src/board/engine.rs index 18abaa0..46cf8ed 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -507,7 +507,7 @@ impl Board { alpha } - pub fn iterative_deepening(&mut self, max_depth: u8, duration: Duration) -> (f32, Vec<Move>) { + pub fn iterative_deepening(&mut self, max_depth: u8, duration: Duration, print: bool) -> (f32, Vec<Move>) { let start = Instant::now(); let deadline = start + duration; let mut result = None; @@ -520,7 +520,9 @@ impl Board { while depth <= max_depth { - println!("\nSearching depth({}) in the window {:?}", depth, (alpha, beta)); + if print { + println!("\nSearching depth({}) in the window {:?}", depth, (alpha, beta)); + } let search_result = self.negamax_search(alpha, beta, depth, &mut root_killers, deadline); if search_result.0.abs() >= VALUE_WIN { @@ -528,21 +530,29 @@ impl Board { } if Instant::now() > deadline { - println!("Aborting..."); + if print { + println!("Aborting..."); + } break; } - println!("Finished depth({}) {:?} [{:?} left]", depth, search_result, deadline - Instant::now()); + if print { + println!("Finished depth({}) {:?} [{:?} left]", depth, search_result, deadline - Instant::now()); + } if search_result.0 <= alpha { // Alpha-cutoff - println!("Alpha cutoff {} <= {:?}", search_result.0, (alpha, beta)); + if print { + println!("Alpha cutoff {} <= {:?}", search_result.0, (alpha, beta)); + } gradual_widening_counter += 1; beta = alpha + window_size * 0.1; alpha = search_result.0 - window_size * 2.0f32.powi(gradual_widening_counter); continue; } if search_result.0 >= beta { // Beta-cutoff - println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0); + if print { + println!("Beta cutoff {:?} <= {}", (alpha, beta), search_result.0); + } gradual_widening_counter += 1; alpha = beta - window_size * 0.1; beta = search_result.0 + window_size * 2.0f32.powi(gradual_widening_counter); @@ -619,7 +629,7 @@ mod tests { fn checkmate() { let fen = String::from("2kr1b1r/pp1npppp/2p1bn2/7q/5B2/2NB1Q1P/PPP1N1P1/2KR3R w - - 0 1"); let mut board = Board::from_FEN(fen); - let (score, pv) = board.iterative_deepening(8, Duration::from_secs(15)); + let (score, pv) = board.iterative_deepening(8, Duration::from_secs(15), true); assert_eq!(score, VALUE_WIN); assert_eq!(pv, vec![ @@ -635,7 +645,7 @@ mod tests { let mut board = Board::from_FEN(fen); board.ply += 1; // TODO: remove me when FEN parsing includes side to move - let (_, pv) = board.iterative_deepening(6, Duration::from_secs(60)); + let (_, pv) = board.iterative_deepening(6, Duration::from_secs(60), true); assert_eq!( pv[0], Move { source: Square::F5, target: Square::H4, kind: MoveKind::Quiet }, @@ -648,7 +658,7 @@ mod tests { let fen = String::from("r1b1k1nr/p4pp1/1pp1p3/4n2p/1b1qP3/1B1P3N/PPPBQPPP/RN2K2R w KQkq - 7 10"); let mut board = Board::from_FEN(fen); - let (_, pv) = board.iterative_deepening(5, Duration::from_secs(60)); + let (_, pv) = board.iterative_deepening(5, Duration::from_secs(60), true); assert_eq!( pv[0], Move { source: Square::C2, target: Square::C3, kind: MoveKind::Quiet }, diff --git a/src/main.rs b/src/main.rs index b5ebc95..ca3fde2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ -use std::{f32::INFINITY, time::{Duration, Instant}}; +use std::time::{Duration, Instant}; use std::env; -use chessnost::{board::{Board, Color}, moves::Move}; +use chessnost::board::{Board, Color}; fn opponent_move(board: &mut Board) { let mov = match board.read_move() { @@ -18,11 +18,11 @@ fn opponent_move(board: &mut Board) { fn computer_move(board: &mut Board, time_left: &mut Duration) { let allowed_move_duration = *time_left / 20; - let max_depth = 6 + (board.ply as i32 / 15) as u8; + let max_depth = 7 + (board.ply as i32 / 15) as u8; println!("~{:?} left, allocating {:?} for a move", time_left, allowed_move_duration); let move_start = Instant::now(); - let (score, pv) = board.iterative_deepening(max_depth, allowed_move_duration); + let (score, pv) = board.iterative_deepening(max_depth, allowed_move_duration, true); let elapsed = move_start.elapsed(); if *time_left >= elapsed { @@ -39,15 +39,13 @@ fn computer_move(board: &mut Board, time_left: &mut Duration) { board.print(); // Ponder for some time - println!("Assuming opponent move from PV: {:?}", pv[1]); + println!("Pondering, assume opponent move from PV: {:?}", pv[1]); let ep_target_before = board.ep_target.clone(); let castling_rights_before = board.castling_rights.clone(); let hash_before = board.hash.clone(); let captured_piece = board.make_move(pv[1]); - board.iterative_deepening(max_depth, Duration::from_secs(3)); + board.iterative_deepening(max_depth, Duration::from_secs(3), false); board.unmake_move(pv[1], captured_piece, ep_target_before, castling_rights_before, hash_before); - - board.print(); } fn main() { |