[][src]Crate rubot

An easily reusable game bot for deterministic games.

It is required to implement the trait Game for your game to use this crate.

Examples

A game where you win by selecting 10.

use std::ops::RangeInclusive;

#[derive(Clone)]
struct ChooseTen;

impl rubot::Game for ChooseTen {
    /// there is only one player, you!
    type Player = ();
    type Action = u8;
    /// did you choose a 10?
    type Fitness = bool;
    type Actions = RangeInclusive<u8>;

    fn actions(&self, _: Self::Player) -> (bool, Self::Actions) {
        (true, 1..=10)
    }

    fn execute(&mut self, action: &u8, _: Self::Player) -> Self::Fitness {
        *action == 10
    }
}

fn main() {
    use rubot::Bot;
    use std::time::Duration;

    let mut bot = Bot::new(());
    assert_eq!(
        bot.select(&ChooseTen, Duration::from_secs(1)),
        Some(10)
    );
}

Please visit the examples folder or the trait Game documentation for more realistic examples.

Re-exports

pub use alpha_beta::Bot;

Modules

alpha_beta

A deterministic game bot using alpha beta pruning.

tree

A tree implementation used in examples and tests.

Structs

Depth

A struct implementing RunCondition returning cancelling the computation once the depth self.0 is reached.

Logger

A struct implementing IntoRunCondition which can be used to log a call to select. For more details you can visit the individual methods.

Steps

Can be converted into RunCondition which returns true for the first self.0 steps. This should only be used for debugging and testing as unlike Duration, ToCompletion or Depth, the total amount of steps needed is not directly indicative of search depth and can change between minor versions.

ToCompletion

A struct implementing RunCondition which always returns true.

Traits

Game

An interface required to interact with GameBots.

IntoRunCondition

Converts a type into a RunCondition used by Bot::select. It is recommended to mostly use Duration.

RunCondition

A condition which indicates if Bot::select should keep on running. It is recommended to use Duration for nearly all use cases.