]> git.scottworley.com Git - pluta-lesnura/blame_incremental - src/main.rs
Start adding smarter play: Try for momentum
[pluta-lesnura] / src / main.rs
... / ...
CommitLineData
1use clap::{Parser, Subcommand, ValueEnum};
2use pluta_lesnura::{momentum_player, 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(Clone, Debug, ValueEnum)]
12enum Strategy {
13 Random,
14 Momentum,
15}
16
17#[derive(Subcommand)]
18enum 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
36fn 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 => Player::new(random_player(*draw_chance)),
48 Strategy::Momentum => Player::new(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}