tune: time limits for games longer than 5'

This commit is contained in:
dogeystamp 2024-12-20 14:59:18 -05:00
parent e44cc0586e
commit ab1dfb3aa1
No known key found for this signature in database
4 changed files with 22 additions and 10 deletions

View File

@ -69,7 +69,7 @@ impl From<Color> for char {
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
enum Piece { pub enum Piece {
Rook, Rook,
Bishop, Bishop,
Knight, Knight,

View File

@ -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) (wtime, btime)
} else { } else {
(btime, wtime) (btime, wtime)
}; };
if ourtime_ms == 0 {
ourtime_ms = 300_000
}
state state
.tx_engine .tx_engine
.send(MsgToEngine::Go(Box::new(GoMessage { .send(MsgToEngine::Go(Box::new(GoMessage {
board: state.board, board: state.board,
config: state.config, 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(); .unwrap();
} }

View File

@ -13,9 +13,9 @@ Copyright © 2024 dogeystamp <dogeystamp@disroot.org>
//! Prelude that you can import entirely to use the library conveniently. //! 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::fen::{FromFen, ToFen};
pub use crate::movegen::{FromUCIAlgebraic, Move, MoveGen, ToUCIAlgebraic}; pub use crate::movegen::{FromUCIAlgebraic, Move, MoveGen, ToUCIAlgebraic};
pub use crate::search::{best_line, best_move, SearchEval, TranspositionTable, EngineState, SearchConfig, TimeLimits}; 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}; pub use crate::coordination::{UCIMode, UCIModeTransition, UCIModeMachine, MsgBestmove, MsgToMain, MsgToEngine, GoMessage};

View File

@ -13,11 +13,8 @@ Copyright © 2024 dogeystamp <dogeystamp@disroot.org>
//! Game-tree search. //! Game-tree search.
use crate::coordination::MsgToEngine; use crate::prelude::*;
use crate::eval::{Eval, EvalInt};
use crate::hash::ZobristTable; use crate::hash::ZobristTable;
use crate::movegen::{Move, MoveGen};
use crate::{Board, Piece};
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::sync::mpsc; use std::sync::mpsc;
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
@ -345,12 +342,19 @@ pub struct TimeLimits {
impl TimeLimits { impl TimeLimits {
/// Make time limits based on wtime, btime (but color-independent). /// 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) // hard timeout (max)
let mut hard_ms = 100_000; let mut hard_ms = 100_000;
// soft timeout (max) // soft timeout (max)
let mut soft_ms = 1_200; 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 }; let factor = if ourtime_ms > 5_000 { 10 } else { 40 };
hard_ms = min(ourtime_ms / factor, hard_ms); hard_ms = min(ourtime_ms / factor, hard_ms);
soft_ms = min(ourtime_ms / 50, soft_ms); soft_ms = min(ourtime_ms / 50, soft_ms);