]> git.scottworley.com Git - pluta-lesnura/blame - src/main.rs
Play multiple games per run
[pluta-lesnura] / src / main.rs
CommitLineData
cc2b69f3
SW
1use clap::{Parser, Subcommand};
2use pluta_lesnura::{play, random_player, Game, Player};
3
4#[derive(Parser)]
5#[command(author, version, about, long_about = None, arg_required_else_help = true)]
6struct Cli {
7 #[command(subcommand)]
8 command: Option<Commands>,
9}
10
11#[derive(Subcommand)]
12enum Commands {
13 /// Runs simulations
14 Sim {
aa849374
SW
15 /// How many games?
16 #[arg(short = 'g', long, default_value_t = 1)]
17 num_games: usize,
cc2b69f3 18 /// How many players?
aa849374 19 #[arg(short = 'p', long)]
cc2b69f3
SW
20 num_players: usize,
21 },
22}
23
24fn main() -> Result<(), &'static str> {
25 let cli = Cli::parse();
26
27 match &cli.command {
aa849374
SW
28 Some(Commands::Sim {
29 num_games,
30 num_players,
31 }) => {
32 for _ in 0..*num_games {
33 let players: Vec<_> = std::iter::from_fn(|| Some(Player::new(random_player)))
34 .take(*num_players)
35 .collect();
36 let mut game = Game::default();
37 for _ in 0..*num_players {
38 game.add_player();
39 }
40 let result = play(game, players)?;
41 println!("Result: {result:?}");
cc2b69f3 42 }
cc2b69f3
SW
43 Ok(())
44 }
45 None => unreachable!(),
46 }
47}