diff --git a/bot/src/lib.rs b/bot/src/lib.rs index 786f3b4..4fc5bda 100644 --- a/bot/src/lib.rs +++ b/bot/src/lib.rs @@ -57,14 +57,7 @@ impl BotStrategy for DefaultStrategy { } fn calculate_adv_points(&self) -> u8 { - let dice_roll_count = self - .get_game() - .players - .get(&self.player_id) - .unwrap() - .dice_roll_count; - let points_rules = PointsRules::new(&Color::White, &self.game.board, self.game.dice); - points_rules.get_points(dice_roll_count).0 + self.calculate_points() } fn choose_move(&self) -> (CheckerMove, CheckerMove) { diff --git a/client_cli/src/app.rs b/client_cli/src/app.rs index 2f5b24b..ccc45da 100644 --- a/client_cli/src/app.rs +++ b/client_cli/src/app.rs @@ -1,3 +1,4 @@ +use bot::{BotStrategy, DefaultStrategy}; use itertools::Itertools; use crate::game_runner::Game; @@ -6,6 +7,7 @@ use store::{CheckerMove, GameEvent, GameState, Stage, TurnStage}; #[derive(Debug, Default)] pub struct AppArgs { pub seed: Option, + pub bot: Option, } // Application. @@ -15,16 +17,33 @@ pub struct App { pub should_quit: bool, pub schools_enabled: bool, pub game: Game, + pub bot_strategies: Vec>, } impl App { // Constructs a new instance of [`App`]. pub fn new(args: AppArgs) -> Self { + let bot_strategies: Vec> = args + .bot + .as_deref() + .map(|str_bots| { + str_bots + .split(",") + .filter_map(|s| match s.trim() { + "dummy" => { + Some(Box::new(DefaultStrategy::default()) as Box) + } + _ => None, + }) + .collect() + }) + .unwrap_or_default(); let schools_enabled = false; Self { game: Game::new(schools_enabled, args.seed.map(|s| s as u64)), should_quit: false, schools_enabled, + bot_strategies, } } diff --git a/client_cli/src/main.rs b/client_cli/src/main.rs index 5f0cde4..ede5840 100644 --- a/client_cli/src/main.rs +++ b/client_cli/src/main.rs @@ -17,7 +17,8 @@ FLAGS: -h, --help Prints help information OPTIONS: - --seed SEED Sets the random generator seed + --seed SEED Sets the random generator seed + --bot STRATEGY_BOT Add a bot player with strategy STRATEGY, a second bot may be added to play against the first : --bot STRATEGY_BOT1,STRATEGY_BOT2 ARGS: @@ -59,6 +60,7 @@ fn parse_args() -> Result { let args = AppArgs { // Parses an optional value that implements `FromStr`. seed: pargs.opt_value_from_str("--seed")?, + bot: pargs.opt_value_from_str("--bot")?, // Parses an optional value from `&str` using a specified function. // width: pargs.opt_value_from_fn("--width", parse_width)?.unwrap_or(10), };