//! A trivial com: it plays a uniformly random legal action every time it is //! asked to act. //! //! Usage: cargo run --example random_com -- --token //! or, running the built binary directly: //! random_com --token [--server ] //! //! --server defaults to https://ws.stargamb.it. use rand::seq::SliceRandom; use sg_sdk::{operate_com, Com, Game}; struct RandomCom; impl Com for RandomCom { fn act(&mut self, game: &Game) -> Vec { // Play one random legal action; the runner calls us again until the // turn ends. (A com could instead return a whole turn's worth at once.) game.legal_actions() .choose(&mut rand::thread_rng()) .cloned() .into_iter() .collect() } } fn main() { if let Err(e) = operate_com("random_com", || RandomCom) { eprintln!("fatal: {e}"); } }