wip
This commit is contained in:
parent
5762187b04
commit
25acc86059
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ FLAGS:
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
|
|
||||||
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),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue