alcibiades 0.3.0

A framework for writing chess engines in Rust
Documentation
//! 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;
}