]>
Commit | Line | Data |
---|---|---|
cc2b69f3 SW |
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 players? | |
16 | #[arg(short, long)] | |
17 | num_players: usize, | |
18 | }, | |
19 | } | |
20 | ||
21 | fn main() -> Result<(), &'static str> { | |
22 | let cli = Cli::parse(); | |
23 | ||
24 | match &cli.command { | |
25 | Some(Commands::Sim { num_players }) => { | |
26 | let players: Vec<_> = std::iter::from_fn(|| Some(Player::new(random_player))) | |
27 | .take(*num_players) | |
28 | .collect(); | |
29 | let mut game = Game::default(); | |
30 | for _ in 0..*num_players { | |
31 | game.add_player(); | |
32 | } | |
33 | let result = play(game, players)?; | |
34 | println!("Result: {result:?}"); | |
35 | Ok(()) | |
36 | } | |
37 | None => unreachable!(), | |
38 | } | |
39 | } |