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