Skip to content

Commit 252bfd9

Browse files
authored
Implement the 'go mate x' uci command (#1076)
Bench: 3204302
1 parent 7dd6b0f commit 252bfd9

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/search.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ pub fn start(td: &mut ThreadData, report: Report, thread_count: usize) {
234234
break;
235235
}
236236

237+
if td.id == 0
238+
&& let Limits::Mate(moves) = td.time_manager.limits()
239+
&& Score::MATE - td.root_moves[0].score.abs() <= moves as i32 * 2
240+
{
241+
td.shared.status.set(Status::STOPPED);
242+
break;
243+
}
244+
237245
let multiplier = || {
238246
let nodes = {
239247
let fraction = td.root_moves[0].nodes as f32 / td.nodes() as f32;

src/time.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub enum Limits {
88
Depth(i32),
99
Time(u64),
1010
Nodes(u64),
11+
Mate(u64),
1112
Fischer(u64, u64),
1213
Cyclic(u64, u64, u64),
1314
}
@@ -69,7 +70,7 @@ impl TimeManager {
6970

7071
pub fn soft_limit(&self, td: &ThreadData, multiplier: impl Fn() -> f32) -> bool {
7172
match self.limits {
72-
Limits::Infinite | Limits::Depth(_) => false,
73+
Limits::Infinite | Limits::Depth(_) | Limits::Mate(_) => false,
7374
Limits::Nodes(maximum) => td.shared.nodes.aggregate() >= maximum,
7475
Limits::Time(maximum) => self.start_time.elapsed() >= Duration::from_millis(maximum),
7576
_ => self.start_time.elapsed() >= Duration::from_secs_f32(self.soft_bound.as_secs_f32() * multiplier()),
@@ -82,7 +83,7 @@ impl TimeManager {
8283
}
8384

8485
match self.limits {
85-
Limits::Infinite | Limits::Depth(_) => false,
86+
Limits::Infinite | Limits::Depth(_) | Limits::Mate(_) => false,
8687
Limits::Nodes(maximum) => td.shared.nodes.aggregate() > maximum,
8788
_ => td.nodes() & 2047 == 2047 && self.start_time.elapsed() >= self.hard_bound,
8889
}

src/uci.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ fn parse_limits(color: Color, tokens: &[&str]) -> Limits {
402402
"depth" if value > 0 => return Limits::Depth(value as i32),
403403
"movetime" if value > 0 => return Limits::Time(value),
404404
"nodes" if value > 0 => return Limits::Nodes(value),
405+
"mate" if value > 0 => return Limits::Mate(value),
405406

406407
"wtime" if Color::White == color => main = Some(value),
407408
"btime" if Color::Black == color => main = Some(value),

0 commit comments

Comments
 (0)