use crate::bot::Bot;
use crate::bot::random_numbers;
use crate::game::GameState;
use rand::rngs::StdRng;
use rand::seq::IndexedRandom;
#[derive(Debug, Clone)]
pub struct RandomBot {
random_numbers: StdRng,
}
impl RandomBot {
pub fn from_entropy() -> Self {
Self::with_seed(None)
}
pub fn seeded(seed: u64) -> Self {
Self::with_seed(Some(seed))
}
pub(crate) fn with_seed(seed: Option<u64>) -> Self {
Self {
random_numbers: random_numbers(seed),
}
}
}
impl Default for RandomBot {
fn default() -> Self {
Self::from_entropy()
}
}
impl Bot for RandomBot {
fn choose_move(&mut self, state: &GameState) -> Option<usize> {
state
.legal_moves()
.choose(&mut self.random_numbers)
.copied()
}
fn name(&self) -> &'static str {
"Random bot"
}
}