diff --git a/src/lib.rs b/src/lib.rs index f45b6a8..378d11c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,7 +69,7 @@ impl From for char { } #[derive(Debug, Copy, Clone, PartialEq, Eq)] -enum Piece { +pub enum Piece { Rook, Bishop, Knight, diff --git a/src/main.rs b/src/main.rs index ee76bd9..0c9ce41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,18 +135,26 @@ fn cmd_go(mut tokens: std::str::SplitWhitespace<'_>, state: &mut MainState) { } } - let (ourtime_ms, theirtime_ms) = if state.board.get_turn() == Color::White { + let (mut ourtime_ms, theirtime_ms) = if state.board.get_turn() == Color::White { (wtime, btime) } else { (btime, wtime) }; + if ourtime_ms == 0 { + ourtime_ms = 300_000 + } + state .tx_engine .send(MsgToEngine::Go(Box::new(GoMessage { board: state.board, config: state.config, - time_lims: TimeLimits::from_ourtime_theirtime(ourtime_ms, theirtime_ms), + time_lims: TimeLimits::from_ourtime_theirtime( + ourtime_ms, + theirtime_ms, + eval_metrics(&state.board), + ), }))) .unwrap(); } diff --git a/src/prelude.rs b/src/prelude.rs index 4513f7e..048f350 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -13,9 +13,9 @@ Copyright © 2024 dogeystamp //! Prelude that you can import entirely to use the library conveniently. -pub use crate::eval::{eval_metrics, EvalMetrics}; +pub use crate::eval::{eval_metrics, EvalMetrics, EvalInt, Eval}; pub use crate::fen::{FromFen, ToFen}; pub use crate::movegen::{FromUCIAlgebraic, Move, MoveGen, ToUCIAlgebraic}; pub use crate::search::{best_line, best_move, SearchEval, TranspositionTable, EngineState, SearchConfig, TimeLimits}; -pub use crate::{Board, Color, BOARD_HEIGHT, BOARD_WIDTH, N_COLORS, N_PIECES, N_SQUARES}; +pub use crate::{Board, Color, BOARD_HEIGHT, BOARD_WIDTH, N_COLORS, N_PIECES, N_SQUARES, ColPiece, Piece}; pub use crate::coordination::{UCIMode, UCIModeTransition, UCIModeMachine, MsgBestmove, MsgToMain, MsgToEngine, GoMessage}; diff --git a/src/search.rs b/src/search.rs index d5c19e4..8e66777 100644 --- a/src/search.rs +++ b/src/search.rs @@ -13,11 +13,8 @@ Copyright © 2024 dogeystamp //! Game-tree search. -use crate::coordination::MsgToEngine; -use crate::eval::{Eval, EvalInt}; +use crate::prelude::*; use crate::hash::ZobristTable; -use crate::movegen::{Move, MoveGen}; -use crate::{Board, Piece}; use std::cmp::{max, min}; use std::sync::mpsc; use std::time::{Instant, Duration}; @@ -345,12 +342,19 @@ pub struct TimeLimits { impl TimeLimits { /// Make time limits based on wtime, btime (but color-independent). - pub fn from_ourtime_theirtime(ourtime_ms: u64, _theirtime_ms: u64) -> TimeLimits { + /// + /// Also takes in eval metrics, for instance to avoid wasting too much time in the opening. + pub fn from_ourtime_theirtime(ourtime_ms: u64, _theirtime_ms: u64, eval: EvalMetrics) -> TimeLimits { // hard timeout (max) let mut hard_ms = 100_000; // soft timeout (max) let mut soft_ms = 1_200; + // if we have more than 5 minutes, and we're out of the opening, we can afford to think longer + if ourtime_ms > 300_000 && eval.phase <= 13 { + soft_ms = 3_000 + } + let factor = if ourtime_ms > 5_000 { 10 } else { 40 }; hard_ms = min(ourtime_ms / factor, hard_ms); soft_ms = min(ourtime_ms / 50, soft_ms);