]> git.scottworley.com Git - pluta-lesnura/blob - src/main.rs
Play multiple games per run
[pluta-lesnura] / src / main.rs
1 use clap::{Parser, Subcommand};
2 use pluta_lesnura::{play, random_player, Game, Player};
3
4 #[derive(Parser)]
5 #[command(author, version, about, long_about = None, arg_required_else_help = true)]
6 struct Cli {
7 #[command(subcommand)]
8 command: Option<Commands>,
9 }
10
11 #[derive(Subcommand)]
12 enum Commands {
13 /// Runs simulations
14 Sim {
15 /// How many games?
16 #[arg(short = 'g', long, default_value_t = 1)]
17 num_games: usize,
18 /// How many players?
19 #[arg(short = 'p', long)]
20 num_players: usize,
21 },
22 }
23
24 fn main() -> Result<(), &'static str> {
25 let cli = Cli::parse();
26
27 match &cli.command {
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:?}");
42 }
43 Ok(())
44 }
45 None => unreachable!(),
46 }
47 }