wip
This commit is contained in:
parent
5762187b04
commit
25acc86059
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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<u32>,
|
||||
pub bot: Option<String>,
|
||||
}
|
||||
|
||||
// Application.
|
||||
|
|
@ -15,16 +17,33 @@ pub struct App {
|
|||
pub should_quit: bool,
|
||||
pub schools_enabled: bool,
|
||||
pub game: Game,
|
||||
pub bot_strategies: Vec<Box<dyn BotStrategy>>,
|
||||
}
|
||||
|
||||
impl App {
|
||||
// Constructs a new instance of [`App`].
|
||||
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;
|
||||
Self {
|
||||
game: Game::new(schools_enabled, args.seed.map(|s| s as u64)),
|
||||
should_quit: false,
|
||||
schools_enabled,
|
||||
bot_strategies,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ FLAGS:
|
|||
|
||||
OPTIONS:
|
||||
--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:
|
||||
<INPUT>
|
||||
|
|
@ -59,6 +60,7 @@ fn parse_args() -> Result<AppArgs, pico_args::Error> {
|
|||
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),
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue