opentttlib

Crates.io Documentation License Build Status Coverage Status

Open source Rust library that provides common Tic Tac Toe logic that can be used by other Rust applications.

Usage

Add this to your Cargo.toml:

toml [dependencies] open_ttt_lib = "0.1.1"

Below is an example of using this library. Two AI opponents to play a game of Tic Tac Toe until one is victorious.

```rust use opentttlib::{ai, game};

fn main() -> Result<(), Box> { // Create a game and two AI opponents to play the game. let mut game = game::Game::new();

// Rando picks random positions.
let rando = ai::Opponent::new(1.0);
// The flawless opponent cannot loose: it fully evaluates every possible
// move and countermove to pick the best position.
let flawless_ai = ai::Opponent::new(0.0);

// Have the opponents take turns making moves until the game is over.
loop {
    match game.state() {
        game::State::PlayerXMove => {
            println!("Rando playing as X turn:");
            game.do_move(rando.get_move(&game).unwrap())?;
        }
        game::State::PlayerOMove => {
            println!("Flawless AI playing as O turn:");
            game.do_move(flawless_ai.get_move(&game).unwrap())?;
        }
        game::State::PlayerXWin(_) => {
            println!("Game Over: Rando playing as X wins!");
            break;
        }
        game::State::PlayerOWin(_) => {
            println!("Game Over: Flawless AI playing as O wins!");
            break;
        }
        game::State::CatsGame => {
            println!("Game Over: cat's game.");
            break;
        }
    };

    // Print the game's the board.
    println!("{}", game.board());
}

Ok(())

} ```

See the documentation for additional examples and details on using the library.

Benchmarks

This library includes benchmarks that you can use to evaluate if the library fits in with your performance goals. Use the following command to run the benchmark suite:

text cargo bench

Feature Requests

Feel free to request new features. File a feature request describing the feature you would like and what benefit you will get from the feature. A user story is one way to capture this information:

As a user I want goal/desire so that benefit.

Reporting Issues

If you find an issue please include the following information in your report:

Contributing

Contributions are welcome! See CONTRIBUTING.md for details on how to contribute to this project.

License

The library is licensed under the MIT license.