refact: BotStrategy dyn trait
This commit is contained in:
parent
4ee2b02a41
commit
5762187b04
6 changed files with 43 additions and 69 deletions
|
|
@ -1,8 +1,7 @@
|
|||
use itertools::Itertools;
|
||||
|
||||
use crate::game_runner::Game;
|
||||
use bot::BotStrategy;
|
||||
use store::{CheckerMove, GameEvent, GameState, PointsRules, Stage, TurnStage};
|
||||
use store::{CheckerMove, GameEvent, GameState, Stage, TurnStage};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct AppArgs {
|
||||
|
|
@ -73,15 +72,15 @@ impl App {
|
|||
let dice = self.game.dice_roller.roll();
|
||||
|
||||
// get correct points for these board and dice
|
||||
let points_rules = PointsRules::new(
|
||||
&self
|
||||
.game
|
||||
.state
|
||||
.player_color_by_id(&self.game.player_id.unwrap())
|
||||
.unwrap(),
|
||||
&self.game.state.board,
|
||||
dice,
|
||||
);
|
||||
// let points_rules = PointsRules::new(
|
||||
// &self
|
||||
// .game
|
||||
// .state
|
||||
// .player_color_by_id(&self.game.player_id.unwrap())
|
||||
// .unwrap(),
|
||||
// &self.game.state.board,
|
||||
// dice,
|
||||
// );
|
||||
self.game.handle_event(&GameEvent::RollResult {
|
||||
player_id: self.game.player_id.unwrap(),
|
||||
dice,
|
||||
|
|
@ -191,10 +190,10 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_display() {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,14 @@
|
|||
use bot::{Bot, BotStrategy, DefaultStrategy};
|
||||
use bot::{Bot, DefaultStrategy};
|
||||
use store::{CheckerMove, DiceRoller, GameEvent, GameState, PlayerId, TurnStage};
|
||||
|
||||
// Application Game
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Game {
|
||||
pub state: GameState,
|
||||
pub dice_roller: DiceRoller,
|
||||
pub first_move: Option<CheckerMove>,
|
||||
pub player_id: Option<PlayerId>,
|
||||
bot: Bot<DefaultStrategy>,
|
||||
}
|
||||
|
||||
impl Default for Game {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
state: GameState::default(),
|
||||
dice_roller: DiceRoller::default(),
|
||||
first_move: None,
|
||||
player_id: None,
|
||||
bot: Bot::default(),
|
||||
}
|
||||
}
|
||||
bot: Bot,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
|
|
@ -32,8 +20,9 @@ impl Game {
|
|||
// bot
|
||||
let bot_id: PlayerId = state.init_player("bot").unwrap();
|
||||
let bot_color = state.player_color_by_id(&bot_id).unwrap();
|
||||
let bot_strategy = DefaultStrategy::default();
|
||||
let bot: Bot<DefaultStrategy> = Bot::new(bot_strategy, bot_color, schools_enabled);
|
||||
let bot_strategy = Box::new(DefaultStrategy::default());
|
||||
// let bot: Bot = Bot::new(bot_strategy, bot_color, schools_enabled);
|
||||
let bot: Bot = Bot::new(bot_strategy, bot_color);
|
||||
|
||||
let mut game = Self {
|
||||
state,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue