]> git.scottworley.com Git - pluta-lesnura/blob - src/main.rs
players are Players
[pluta-lesnura] / src / main.rs
1 use clap::{Parser, Subcommand, ValueEnum};
2 use pluta_lesnura::{momentum_player, play, random_player, Game};
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(Clone, Debug, ValueEnum)]
12 enum Strategy {
13 Random,
14 Momentum,
15 }
16
17 #[derive(Subcommand)]
18 enum Commands {
19 /// Runs simulations
20 Sim {
21 /// For momentum play, draw how often? 0-1
22 #[arg(short = 'p', long, default_value_t = 0.5)]
23 draw_chance: f64,
24 /// How many games?
25 #[arg(short = 'g', long, default_value_t = 1)]
26 num_games: usize,
27 /// How many players?
28 #[arg(short = 'p', long)]
29 num_players: usize,
30 /// What strategy should players use?
31 #[arg(short = 's', long, value_enum)]
32 strategy: Strategy,
33 },
34 }
35
36 fn main() -> Result<(), &'static str> {
37 let cli = Cli::parse();
38
39 match &cli.command {
40 Some(Commands::Sim {
41 draw_chance,
42 num_games,
43 num_players,
44 strategy,
45 }) => {
46 let player = || match strategy {
47 Strategy::Random => random_player(*draw_chance),
48 Strategy::Momentum => momentum_player(*draw_chance),
49 };
50 for _ in 0..*num_games {
51 let players: Vec<_> = std::iter::from_fn(|| Some(player()))
52 .take(*num_players)
53 .collect();
54 let mut game = Game::default();
55 for _ in 0..*num_players {
56 game.add_player();
57 }
58 let result = play(game, players)?;
59 println!("Result: {result:?}");
60 }
61 Ok(())
62 }
63 None => unreachable!(),
64 }
65 }