mancala::game

Struct Game

Source
pub struct Game {
    pub current: Position,
    /* private fields */
}
Expand description

Game is an sequence of Positions.

A Game is created with a GameBuilder.

Fields§

§current: Position

The current position of this game

Implementations§

Source§

impl Game

Source

pub fn finished(&self) -> bool

Determine if this game is finished

Source

pub fn options(&self) -> Vec<Bowl>

Determine which bowls are playable.

Source

pub fn play(&mut self, bowl: Bowl) -> Result<(), FoulPlay>

Play a certain bowl.

Fails if the bowl does not contain any stones.

Source

pub fn score(&self) -> Option<Score>

Determine the score of a game.

None if the game is not finished

Examples found in repository?
examples/minmax.rs (line 16)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut red_strategy = MinMax {};
    let mut blue_strategy = MinMax {};
    let mut bout = Bout::new(&mut red_strategy, &mut blue_strategy);

    for stones in 1..15 {
        let game = GameBuilder::new().bowls(2).stones(stones).build();
        let result = bout.start(game).expect("a finished game with score");
        let score = result
            .score()
            .map(|score| score * score_multiplier(result.current.active_player()));
        println!("{} {:?}", stones, score);
    }
}
More examples
Hide additional examples
examples/alphabeta.rs (line 16)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut red_strategy = AlphaBeta::strategy().build();
    let mut blue_strategy = AlphaBeta::strategy().build();
    let mut bout = Bout::new(&mut red_strategy, &mut blue_strategy);

    for stones in 1..15 {
        let game = GameBuilder::new().bowls(2).stones(stones).build();
        let result = bout.start(game).expect("a finished game with score");
        let score = result
            .score()
            .map(|score| score * score_multiplier(result.current.active_player()));
        println!("{} {:?}", stones, score);
    }
}
Source

pub fn turn(&self) -> Player

Return which players turn it is

Trait Implementations§

Source§

impl Debug for Game

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Game

Source§

fn eq(&self, other: &Game) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Game

Auto Trait Implementations§

§

impl Freeze for Game

§

impl RefUnwindSafe for Game

§

impl Send for Game

§

impl Sync for Game

§

impl Unpin for Game

§

impl UnwindSafe for Game

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.