Something went wrong. Try again.
Star Gambit Computer Player SDK
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132//! A trivial com: it plays a uniformly random legal action every time it is//! asked to act.//!//! Usage: cargo run --example random_com -- --token <api_token>//! or, running the built binary directly://! random_com --token <api_token> [--server <url>]//!//! --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<String> { // 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}"); }}