[−][src]Enum shogi::time::TimeControl
Represents various time controls.
Currently Byo-yomi and Fischer Clock are supported.
Examples
use std::time::Duration; use shogi::{Color, TimeControl}; let mut byoyomi = TimeControl::Byoyomi{ black_time: Duration::from_secs(10), white_time: Duration::from_secs(10), byoyomi: Duration::from_secs(5) }; // Black player can use the time up to black_time + byoyomi. byoyomi.consume(Color::Black, Duration::from_secs(15)); assert_eq!(Duration::from_secs(0), byoyomi.black_time()); assert_eq!(Duration::from_secs(10), byoyomi.white_time());
use std::time::Duration; use shogi::{Color, TimeControl}; let mut fischer_clock = TimeControl::FischerClock{ black_time: Duration::from_secs(10), white_time: Duration::from_secs(10), black_inc: Duration::from_secs(1), white_inc: Duration::from_secs(1) }; // White player gets additional 1 second after the black move. fischer_clock.consume(Color::Black, Duration::from_secs(3)); assert_eq!(Duration::from_secs(7), fischer_clock.black_time()); assert_eq!(Duration::from_secs(11), fischer_clock.white_time());
Variants
Fields of FischerClock
Implementations
impl TimeControl
[src]
pub fn black_time(&self) -> Duration
[src]
Returns the current remaining time for the black player.
pub fn white_time(&self) -> Duration
[src]
Returns the current remaining time for the white player.
pub fn consume(&mut self, c: Color, d: Duration) -> bool
[src]
Updates the current remaining time after consuming the given amount of time for the given player.
Returns false if the given player runs out of time, true otherwise.
Examples
use std::time::Duration; use shogi::{Color, TimeControl}; let mut byoyomi = TimeControl::Byoyomi{ black_time: Duration::from_secs(10), white_time: Duration::from_secs(10), byoyomi: Duration::from_secs(5) }; assert!(byoyomi.consume(Color::Black, Duration::from_secs(15))); assert!(!byoyomi.consume(Color::White, Duration::from_secs(20)));
Trait Implementations
impl Clone for TimeControl
[src]
fn clone(&self) -> TimeControl
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for TimeControl
[src]
impl Debug for TimeControl
[src]
Auto Trait Implementations
impl RefUnwindSafe for TimeControl
impl Send for TimeControl
impl Sync for TimeControl
impl Unpin for TimeControl
impl UnwindSafe for TimeControl
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,