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
impl Game
Sourcepub fn play(&mut self, bowl: Bowl) -> Result<(), FoulPlay>
pub fn play(&mut self, bowl: Bowl) -> Result<(), FoulPlay>
Play a certain bowl.
Fails if the bowl does not contain any stones.
Sourcepub fn score(&self) -> Option<Score>
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
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);
}
}
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more