Enum shogi::time::TimeControl[][src]

pub enum TimeControl {
    Byoyomi {
        black_time: Duration,
        white_time: Duration,
        byoyomi: Duration,
    },
    FischerClock {
        black_time: Duration,
        white_time: Duration,
        black_inc: Duration,
        white_inc: Duration,
    },
}
Expand description

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(8), fischer_clock.black_time());
assert_eq!(Duration::from_secs(10), fischer_clock.white_time());

Variants

Byoyomi

Fields

black_time: Duration
white_time: Duration
byoyomi: Duration

FischerClock

Fields

black_time: Duration
white_time: Duration
black_inc: Duration
white_inc: Duration

Implementations

Returns the current remaining time for the black player.

Returns the current remaining time for the white player.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.