Struct open_ttt_lib::ai::Opponent [−][src]
pub struct Opponent { /* fields omitted */ }
Expand description
Provides a computer controlled AI opponent.
This can be used to create single player games or implement a hint system for human users.
Implementations
impl Opponent
[src]
impl Opponent
[src]pub fn new(difficulty: Difficulty) -> Self
[src]
pub fn new(difficulty: Difficulty) -> Self
[src]Constructs a new AI opponent using the provided difficulty.
Examples
Construct a hard AI opponent:
use open_ttt_lib::ai; let hard_opponent = ai::Opponent::new(ai::Difficulty::Hard);
Construct an AI opponent that randomly picks positions:
use open_ttt_lib::ai; let rando = ai::Opponent::new(ai::Difficulty::None);
pub fn get_move(&self, game: &Game) -> Option<Position>
[src]
pub fn get_move(&self, game: &Game) -> Option<Position>
[src]Gets the position the AI opponent wishes to move based on the provided game.
None
is returned if the game is over. The AI opponent never tries to
select an invalid position, that is a position that is not free.
Examples
use open_ttt_lib::ai; use open_ttt_lib::game; let game = game::Game::new(); let ai_opponent = ai::Opponent::new(ai::Difficulty::Medium); match ai_opponent.get_move(&game) { Some(position) => assert!(game.can_move(position)), None => panic!("The game is over so the AI opponent cannot do a move."), };
pub fn evaluate_game(&self, game: &Game) -> HashMap<Position, Outcome>
[src]
pub fn evaluate_game(&self, game: &Game) -> HashMap<Position, Outcome>
[src]Evaluates each free position in the provided game.
Each free position in the game is mapped to an outcome for the AI opponent. If the game is over an empty map is returned.
This functionality is useful if you wish to examine how the AI opponent viewed the game. E.g. this can be helpful for creating a hint system to help human players pick a position or when fine-tuning the AI difficulty settings.
Examples
use open_ttt_lib::ai; use open_ttt_lib::game; let game = game::Game::new(); let ai_opponent = ai::Opponent::new(ai::Difficulty::Medium); let outcomes = ai_opponent.evaluate_game(&game); // Display the outcome for each position. for (position, outcome) in outcomes { assert!(game.can_move(position)); println!("position: {:?} outcome: {:?}", position, outcome); }
Trait Implementations
impl StructuralPartialEq for Opponent
[src]
Auto Trait Implementations
impl RefUnwindSafe for Opponent
impl Send for Opponent
impl Sync for Opponent
impl Unpin for Opponent
impl UnwindSafe for Opponent
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,