This commit is contained in:
Henri Bourcereau 2024-11-05 18:03:14 +01:00
parent 5762187b04
commit 25acc86059
3 changed files with 23 additions and 9 deletions

View file

@ -57,14 +57,7 @@ impl BotStrategy for DefaultStrategy {
} }
fn calculate_adv_points(&self) -> u8 { fn calculate_adv_points(&self) -> u8 {
let dice_roll_count = self self.calculate_points()
.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
} }
fn choose_move(&self) -> (CheckerMove, CheckerMove) { fn choose_move(&self) -> (CheckerMove, CheckerMove) {

View file

@ -1,3 +1,4 @@
use bot::{BotStrategy, DefaultStrategy};
use itertools::Itertools; use itertools::Itertools;
use crate::game_runner::Game; use crate::game_runner::Game;
@ -6,6 +7,7 @@ use store::{CheckerMove, GameEvent, GameState, Stage, TurnStage};
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct AppArgs { pub struct AppArgs {
pub seed: Option<u32>, pub seed: Option<u32>,
pub bot: Option<String>,
} }
// Application. // Application.
@ -15,16 +17,33 @@ pub struct App {
pub should_quit: bool, pub should_quit: bool,
pub schools_enabled: bool, pub schools_enabled: bool,
pub game: Game, pub game: Game,
pub bot_strategies: Vec<Box<dyn BotStrategy>>,
} }
impl App { impl App {
// Constructs a new instance of [`App`]. // Constructs a new instance of [`App`].
pub fn new(args: AppArgs) -> Self { pub fn new(args: AppArgs) -> Self {
let bot_strategies: Vec<Box<dyn BotStrategy>> = args
.bot
.as_deref()
.map(|str_bots| {
str_bots
.split(",")
.filter_map(|s| match s.trim() {
"dummy" => {
Some(Box::new(DefaultStrategy::default()) as Box<dyn BotStrategy>)
}
_ => None,
})
.collect()
})
.unwrap_or_default();
let schools_enabled = false; let schools_enabled = false;
Self { Self {
game: Game::new(schools_enabled, args.seed.map(|s| s as u64)), game: Game::new(schools_enabled, args.seed.map(|s| s as u64)),
should_quit: false, should_quit: false,
schools_enabled, schools_enabled,
bot_strategies,
} }
} }

View file

@ -18,6 +18,7 @@ FLAGS:
OPTIONS: 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: ARGS:
<INPUT> <INPUT>
@ -59,6 +60,7 @@ fn parse_args() -> Result<AppArgs, pico_args::Error> {
let args = AppArgs { let args = AppArgs {
// Parses an optional value that implements `FromStr`. // Parses an optional value that implements `FromStr`.
seed: pargs.opt_value_from_str("--seed")?, seed: pargs.opt_value_from_str("--seed")?,
bot: pargs.opt_value_from_str("--bot")?,
// Parses an optional value from `&str` using a specified function. // Parses an optional value from `&str` using a specified function.
// width: pargs.opt_value_from_fn("--width", parse_width)?.unwrap_or(10), // width: pargs.opt_value_from_fn("--width", parse_width)?.unwrap_or(10),
}; };