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