diff --git a/bot/src/lib.rs b/bot/src/lib.rs index f3e1258..8612347 100644 --- a/bot/src/lib.rs +++ b/bot/src/lib.rs @@ -2,6 +2,7 @@ mod strategy; use store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage}; pub use strategy::default::DefaultStrategy; +pub use strategy::erroneous_moves::ErroneousStrategy; pub use strategy::stable_baselines3::StableBaselines3Strategy; pub trait BotStrategy: std::fmt::Debug { diff --git a/bot/src/strategy.rs b/bot/src/strategy.rs index 6d144fb..7667f6d 100644 --- a/bot/src/strategy.rs +++ b/bot/src/strategy.rs @@ -1,3 +1,4 @@ pub mod client; pub mod default; +pub mod erroneous_moves; pub mod stable_baselines3; diff --git a/bot/src/strategy/erroneous_moves.rs b/bot/src/strategy/erroneous_moves.rs new file mode 100644 index 0000000..3f26f28 --- /dev/null +++ b/bot/src/strategy/erroneous_moves.rs @@ -0,0 +1,63 @@ +use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId, PointsRules}; +use store::MoveRules; + +#[derive(Debug)] +pub struct ErroneousStrategy { + pub game: GameState, + pub player_id: PlayerId, + pub color: Color, +} + +impl Default for ErroneousStrategy { + fn default() -> Self { + let game = GameState::default(); + Self { + game, + player_id: 2, + color: Color::Black, + } + } +} + +impl BotStrategy for ErroneousStrategy { + fn get_game(&self) -> &GameState { + &self.game + } + fn get_mut_game(&mut self) -> &mut GameState { + &mut self.game + } + + fn set_color(&mut self, color: Color) { + self.color = color; + } + + fn set_player_id(&mut self, player_id: PlayerId) { + self.player_id = player_id; + } + + fn calculate_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 + } + + fn calculate_adv_points(&self) -> u8 { + self.calculate_points() + } + + fn choose_go(&self) -> bool { + true + } + + fn choose_move(&self) -> (CheckerMove, CheckerMove) { + ( + CheckerMove::new(1, 10).unwrap(), + CheckerMove::new(2, 7).unwrap(), + ) + } +} diff --git a/client_cli/src/app.rs b/client_cli/src/app.rs index a2f5244..a312206 100644 --- a/client_cli/src/app.rs +++ b/client_cli/src/app.rs @@ -1,4 +1,4 @@ -use bot::{BotStrategy, DefaultStrategy, StableBaselines3Strategy}; +use bot::{BotStrategy, DefaultStrategy, ErroneousStrategy, StableBaselines3Strategy}; use itertools::Itertools; use crate::game_runner::GameRunner; @@ -22,28 +22,31 @@ pub struct App { 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) - } - "ai" => { - Some(Box::new(StableBaselines3Strategy::default()) as Box) - } - s if s.starts_with("ai:") => { - let path = s.trim_start_matches("ai:"); - Some(Box::new(StableBaselines3Strategy::new(path)) as Box) - } - _ => None, - }) - .collect() - }) - .unwrap_or_default(); + 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) + } + "erroneous" => { + Some(Box::new(ErroneousStrategy::default()) as Box) + } + "ai" => Some(Box::new(StableBaselines3Strategy::default()) + as Box), + s if s.starts_with("ai:") => { + let path = s.trim_start_matches("ai:"); + Some(Box::new(StableBaselines3Strategy::new(path)) + as Box) + } + _ => None, + }) + .collect() + }) + .unwrap_or_default(); let schools_enabled = false; let should_quit = bot_strategies.len() > 1; Self { diff --git a/devenv.lock b/devenv.lock index 7ad7913..8ea6285 100644 --- a/devenv.lock +++ b/devenv.lock @@ -31,10 +31,31 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1742058297, + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "59f17850021620cd348ad2e9c0c64f4e6325ce2a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ - "pre-commit-hooks", + "git-hooks", "nixpkgs" ] }, @@ -66,32 +87,14 @@ "type": "github" } }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1740915799, - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "42b1ba089d2034d910566bf6b40830af6b8ec732", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, "root": { "inputs": { "devenv": "devenv", + "git-hooks": "git-hooks", "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" + "pre-commit-hooks": [ + "git-hooks" + ] } } }, diff --git a/justfile b/justfile index 7c2b61a..d7b450c 100644 --- a/justfile +++ b/justfile @@ -9,7 +9,7 @@ shell: runcli: RUST_LOG=info cargo run --bin=client_cli runclibots: - RUST_LOG=info cargo run --bin=client_cli -- --bot dummy,dummy + RUST_LOG=info cargo run --bin=client_cli -- --bot dummy,ai profile: echo '1' | sudo tee /proc/sys/kernel/perf_event_paranoid cargo build --profile profiling