[−][src]Struct open_ttt_lib::ai::Opponent
Provides a computer controlled AI opponent.
This can be used to create single player games or implement a hint system for human users.
Methods
impl Opponent
[src]
pub fn new(mistake_probability: f64) -> Self
[src]
Constructs a new AI opponent.
The mistake probability indicates how likely the AI will fail to consider various situations. A value of 0.0 makes the AI play a perfect game. A value of 1.0 causes the AI to always pick a random position. Values less than 0.0 are set to 0.0 and values greater than 1.0 are set to 1.0.
Examples
Construct an unbeatable AI opponent:
use open_ttt_lib::ai; let mistake_probability = 0.0; let unbeatable_opponent = ai::Opponent::new(mistake_probability);
Construct an AI opponent that randomly picks a position:
use open_ttt_lib::ai; let mistake_probability = 1.0; let rando = ai::Opponent::new(mistake_probability);
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(0.0); 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]
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(0.0); 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); }
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,