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