bot : erroneous strategy
This commit is contained in:
parent
ab770f3a34
commit
27fc08c47d
|
|
@ -2,6 +2,7 @@ mod strategy;
|
||||||
|
|
||||||
use store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
use store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||||
pub use strategy::default::DefaultStrategy;
|
pub use strategy::default::DefaultStrategy;
|
||||||
|
pub use strategy::erroneous_moves::ErroneousStrategy;
|
||||||
pub use strategy::stable_baselines3::StableBaselines3Strategy;
|
pub use strategy::stable_baselines3::StableBaselines3Strategy;
|
||||||
|
|
||||||
pub trait BotStrategy: std::fmt::Debug {
|
pub trait BotStrategy: std::fmt::Debug {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod default;
|
pub mod default;
|
||||||
|
pub mod erroneous_moves;
|
||||||
pub mod stable_baselines3;
|
pub mod stable_baselines3;
|
||||||
|
|
|
||||||
63
bot/src/strategy/erroneous_moves.rs
Normal file
63
bot/src/strategy/erroneous_moves.rs
Normal file
|
|
@ -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(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use bot::{BotStrategy, DefaultStrategy, StableBaselines3Strategy};
|
use bot::{BotStrategy, DefaultStrategy, ErroneousStrategy, StableBaselines3Strategy};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::game_runner::GameRunner;
|
use crate::game_runner::GameRunner;
|
||||||
|
|
@ -22,28 +22,31 @@ pub struct App {
|
||||||
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
|
let bot_strategies: Vec<Box<dyn BotStrategy>> =
|
||||||
.bot
|
args.bot
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|str_bots| {
|
.map(|str_bots| {
|
||||||
str_bots
|
str_bots
|
||||||
.split(",")
|
.split(",")
|
||||||
.filter_map(|s| match s.trim() {
|
.filter_map(|s| match s.trim() {
|
||||||
"dummy" => {
|
"dummy" => {
|
||||||
Some(Box::new(DefaultStrategy::default()) as Box<dyn BotStrategy>)
|
Some(Box::new(DefaultStrategy::default()) as Box<dyn BotStrategy>)
|
||||||
}
|
}
|
||||||
"ai" => {
|
"erroneous" => {
|
||||||
Some(Box::new(StableBaselines3Strategy::default()) as Box<dyn BotStrategy>)
|
Some(Box::new(ErroneousStrategy::default()) as Box<dyn BotStrategy>)
|
||||||
}
|
}
|
||||||
s if s.starts_with("ai:") => {
|
"ai" => Some(Box::new(StableBaselines3Strategy::default())
|
||||||
let path = s.trim_start_matches("ai:");
|
as Box<dyn BotStrategy>),
|
||||||
Some(Box::new(StableBaselines3Strategy::new(path)) as Box<dyn BotStrategy>)
|
s if s.starts_with("ai:") => {
|
||||||
}
|
let path = s.trim_start_matches("ai:");
|
||||||
_ => None,
|
Some(Box::new(StableBaselines3Strategy::new(path))
|
||||||
})
|
as Box<dyn BotStrategy>)
|
||||||
.collect()
|
}
|
||||||
})
|
_ => None,
|
||||||
.unwrap_or_default();
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
let schools_enabled = false;
|
let schools_enabled = false;
|
||||||
let should_quit = bot_strategies.len() > 1;
|
let should_quit = bot_strategies.len() > 1;
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
49
devenv.lock
49
devenv.lock
|
|
@ -31,10 +31,31 @@
|
||||||
"type": "github"
|
"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": {
|
"gitignore": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"pre-commit-hooks",
|
"git-hooks",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -66,32 +87,14 @@
|
||||||
"type": "github"
|
"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": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"devenv": "devenv",
|
"devenv": "devenv",
|
||||||
|
"git-hooks": "git-hooks",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"pre-commit-hooks": "pre-commit-hooks"
|
"pre-commit-hooks": [
|
||||||
|
"git-hooks"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
2
justfile
2
justfile
|
|
@ -9,7 +9,7 @@ shell:
|
||||||
runcli:
|
runcli:
|
||||||
RUST_LOG=info cargo run --bin=client_cli
|
RUST_LOG=info cargo run --bin=client_cli
|
||||||
runclibots:
|
runclibots:
|
||||||
RUST_LOG=info cargo run --bin=client_cli -- --bot dummy,dummy
|
RUST_LOG=info cargo run --bin=client_cli -- --bot dummy,ai
|
||||||
profile:
|
profile:
|
||||||
echo '1' | sudo tee /proc/sys/kernel/perf_event_paranoid
|
echo '1' | sudo tee /proc/sys/kernel/perf_event_paranoid
|
||||||
cargo build --profile profiling
|
cargo build --profile profiling
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue