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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//! Defines the `TimeManager` trait. use uci::SetOption; use ttable::Variation; use search::*; /// Describes the remaining time on the clocks. #[derive(Clone, Debug)] pub struct RemainingTime { /// The remaining time in milliseconds for white. pub white_millis: u64, /// The remaining time in milliseconds for black. pub black_millis: u64, /// The number of milliseconds with which white's remaining time /// is incremented on each move. pub winc_millis: u64, /// The number of milliseconds with which black's remaining time /// is incremented on each move. pub binc_millis: u64, /// The number of moves to the next time control. /// /// Can not be zero. pub movestogo: Option<u64>, } /// A trait for deciding when the search must be terminated and the /// best move played. /// /// To implement your own time management logic, you must define a /// type that implements the `TimeManager` trait. pub trait TimeManager<T: DeepeningSearch<ReportData = Vec<Variation>>> : SetOption { /// Creates a new instance. /// /// * `position` gives the current position. /// /// * `time` gives the remaining time on the clocks. fn new(position: &T::SearchNode, time: &RemainingTime) -> Self; /// Returns `true` if the search must be terminated and the best /// move played. /// /// * `search_instance` is a mutable reference to the currently /// running search instance. The time manager should be careful /// when calling methods on the currently running search /// instance, so as not to disturb its normal working. In /// particular, `start_search` and `try_recv_report` methods /// must not be called, and a `"TERMINATE"` message must not be /// sent. /// /// * `report`, when supplied, gives a reference to an incoming /// search progress report. `must_play` will be called exactly /// once for each progress report generated by the search, /// following the order in which the reports have been /// generated. fn must_play(&mut self, search_instance: &mut T, report: Option<&SearchReport<Vec<Variation>>>) -> bool; }