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