use turnbase::{Game, PlayerId, Prng};
use crate::Bot;
pub struct Random {
rng: Prng,
}
impl Random {
#[must_use]
pub const fn new(seed: u64) -> Self {
Self {
rng: Prng::new(seed),
}
}
}
impl<G: Game> Bot<G> for Random {
fn choose(&mut self, game: &G, state: &G::State, player: PlayerId) -> Option<G::Action> {
let mut actions = game.legal_actions(state, player);
if actions.is_empty() {
return None;
}
#[allow(clippy::cast_possible_truncation)]
let index = self.rng.below(actions.len() as u64) as usize;
Some(actions.swap_remove(index))
}
}