Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/search/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl SearchData {
shared,
pv: PVTable::new(),
board: Board::from_fen(STARTING_FEN).unwrap(),
time: TimeManager::new(Limit::Infinite, 0),
time: TimeManager::new(Limit::Infinite, 0, 0),
report: Report::None,
stack: Stack::new(),
root_moves: Vec::new(),
Expand Down
12 changes: 6 additions & 6 deletions src/search/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::{Duration, Instant};

use crate::{search::data::SearchData, types::MOVE_OVERHEAD};
use crate::search::data::SearchData;

#[derive(Debug, Clone)]
pub struct TimeManager {
Expand Down Expand Up @@ -28,15 +28,15 @@ pub enum Limit {
}

impl TimeManager {
pub fn new(limit: Limit, full_moves: usize) -> TimeManager {
pub fn new(limit: Limit, full_moves: usize, overhead: u64) -> TimeManager {
let soft_bound;
let hard_bound;

match limit {
Limit::Fischer(main, inc) => {
let soft_scale = 0.06 - 0.05 * (-0.035 * full_moves as f64).exp();
let hard_scale = 0.75;
let max_time = main.saturating_sub(MOVE_OVERHEAD);
let max_time = main.saturating_sub(overhead);

let soft = (soft_scale * max_time as f64 + inc as f64 * 0.75) as u64;
let hard = (hard_scale * max_time as f64 + inc as f64 * 0.75) as u64;
Expand All @@ -45,15 +45,15 @@ impl TimeManager {
hard_bound = Some(Duration::from_millis(hard.min(max_time)));
}
Limit::Cyclic(main, inc, moves) => {
let max_time = main.saturating_sub(MOVE_OVERHEAD);
let max_time = main.saturating_sub(overhead);
let base = (max_time as f64 / moves as f64) + inc as f64 * 0.75;

soft_bound = Some(Duration::from_millis(((1.0 * base) as u64).min(max_time)));
hard_bound = Some(Duration::from_millis(((5.0 * base) as u64).min(max_time)));
}
Limit::Exact(main) => {
soft_bound = Some(Duration::from_millis(main.saturating_sub(MOVE_OVERHEAD)));
hard_bound = Some(Duration::from_millis(main.saturating_sub(MOVE_OVERHEAD)));
soft_bound = Some(Duration::from_millis(main.saturating_sub(overhead)));
hard_bound = Some(Duration::from_millis(main.saturating_sub(overhead)));
}
_ => {
soft_bound = None;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn bench() -> (u64, u64) {
let mut total_node_count = 0;
for fen in positions {
let board = Board::from_fen(fen).unwrap();
let time_manager = TimeManager::new(Limit::Depth(12), 0);
let time_manager = TimeManager::new(Limit::Depth(12), 0, 0);

pool.start(
&board,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/datagen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn generate_random_opening(
}

fn validation_search(data: &mut SearchData, limit: Limit) {
data.time = TimeManager::new(limit, 0);
data.time = TimeManager::new(limit, 0, 0);
data.shared.reset_all_nodes();
data.shared.status.run();
data.root_moves = data
Expand Down
10 changes: 9 additions & 1 deletion src/tools/uci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct UCISettings {
pub soft_nodes: bool,
pub frc: bool,
pub report: Report,
pub overhead: u64,
}

impl Default for UCISettings {
Expand All @@ -24,6 +25,7 @@ impl Default for UCISettings {
soft_nodes: false,
frc: false,
report: Report::Full,
overhead: 50,
}
}
}
Expand Down Expand Up @@ -213,6 +215,11 @@ pub fn set_option(args: &str, uci_settings: &mut UCISettings, shared: Arc<Shared
shared.set_show_wdl(v);
println!("info string Set UCI_ShowWDL to {v}");
}
["name", "moveoverhead", "value", v] => {
let v = v.parse().unwrap_or(50);
uci_settings.overhead = v;
println!("info string Set MoveOverhead to {v}");
}
#[cfg(feature = "tuning")]
["name", name, "value", amount] => {
match amount.parse::<i32>() {
Expand Down Expand Up @@ -241,7 +248,7 @@ pub fn go(args: &str, pool: &mut SearchThreads, board: &mut Board, uci_settings:
.collect();
}

let time = TimeManager::new(limit, board.state.full_move);
let time = TimeManager::new(limit, board.state.full_move, uci_settings.overhead);
pool.start(board, time, uci_settings.report, movestosearch)
}

Expand Down Expand Up @@ -291,6 +298,7 @@ pub fn uci() {
println!("option name Minimal type check default false");
println!("option name SoftNodes type check default false");
println!("option name UCI_ShowWDL type check default true");
println!("option name MoveOverhead type spin default 50 min 0 max 2000");
#[cfg(feature = "tuning")]
list_params();
println!("uciok");
Expand Down
2 changes: 0 additions & 2 deletions src/types/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ pub const KING_TO: [[Square; 2]; 2] = [[Square::G1, Square::C1], [Square::G8, Sq
pub const MAX_PLY: usize = 248;
pub const MAX_MOVE_NUM: usize = 256;

pub const MOVE_OVERHEAD: u64 = 50;

pub const fn to_file_bb(square: Square) -> BitBoard {
let file = square.to_file();
BitBoard(A_FILE).shift(EAST * file as i8)
Expand Down
Loading