1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::search::negascout::SearchContext;
use std::time::Duration;
pub trait SearchTerminator {
fn should_terminate(&self, ctx: &SearchContext) -> bool;
}
impl SearchTerminator for Duration {
fn should_terminate(&self, ctx: &SearchContext) -> bool {
ctx.start_time.elapsed() > *self
}
}
impl SearchTerminator for usize {
fn should_terminate(&self, ctx: &SearchContext) -> bool {
ctx.depth_remaining > *self
}
}
impl SearchTerminator for (Duration, usize) {
fn should_terminate(&self, ctx: &SearchContext) -> bool {
self.0.should_terminate(ctx) || self.1.should_terminate(ctx)
}
}