]> git.scottworley.com Git - pluta-lesnura/blob - src/main.rs
Configurable draw chance for momentum play
[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 /// For momentum play, draw how often? 0-1
16 #[arg(short = 'p', long, default_value_t = 0.5)]
17 draw_chance: f64,
18 /// How many games?
19 #[arg(short = 'g', long, default_value_t = 1)]
20 num_games: usize,
21 /// How many players?
22 #[arg(short = 'p', long)]
23 num_players: usize,
24 },
25 }
26
27 fn main() -> Result<(), &'static str> {
28 let cli = Cli::parse();
29
30 match &cli.command {
31 Some(Commands::Sim {
32 draw_chance,
33 num_games,
34 num_players,
35 }) => {
36 for _ in 0..*num_games {
37 let players: Vec<_> =
38 std::iter::from_fn(|| Some(Player::new(random_player(*draw_chance))))
39 .take(*num_players)
40 .collect();
41 let mut game = Game::default();
42 for _ in 0..*num_players {
43 game.add_player();
44 }
45 let result = play(game, players)?;
46 println!("Result: {result:?}");
47 }
48 Ok(())
49 }
50 None => unreachable!(),
51 }
52 }