chore(refact): rename modules with 'trictrac-' prefixes
This commit is contained in:
parent
3ab0ad7a56
commit
20b5920718
20 changed files with 134 additions and 156 deletions
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "bot"
|
||||
name = "trictrac-bot"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ path = "src/burnrl/main.rs"
|
|||
pretty_assertions = "1.4.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
store = { path = "../store" }
|
||||
trictrac-store = { path = "../store" }
|
||||
rand = "0.9"
|
||||
env_logger = "0.10"
|
||||
burn = { version = "0.20", features = ["ndarray", "autodiff"] }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import store
|
||||
import trictrac_store
|
||||
|
||||
game = store.TricTrac()
|
||||
print(game.get_state_dict())
|
||||
game = trictrac_store.TricTrac()
|
||||
print(game.get_active_player_id())
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::training_common;
|
|||
use burn::{prelude::Backend, tensor::Tensor};
|
||||
use burn_rl::base::{Action, Environment, Snapshot, State};
|
||||
use rand::{rng, Rng};
|
||||
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||
use trictrac_store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||
|
||||
const ERROR_REWARD: f32 = -1.0012121;
|
||||
const REWARD_VALID_MOVE: f32 = 1.0012121;
|
||||
|
|
@ -292,7 +292,7 @@ impl TrictracEnvironment {
|
|||
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
||||
let dice_event = GameEvent::RollResult {
|
||||
player_id: self.active_player_id,
|
||||
dice: store::Dice {
|
||||
dice: trictrac_store::Dice {
|
||||
values: dice_values,
|
||||
},
|
||||
};
|
||||
|
|
@ -340,7 +340,7 @@ impl TrictracEnvironment {
|
|||
|
||||
// Exécuter l'action selon le turn_stage
|
||||
let mut calculate_points = false;
|
||||
let opponent_color = store::Color::Black;
|
||||
let opponent_color = trictrac_store::Color::Black;
|
||||
let event = match self.game.turn_stage {
|
||||
TurnStage::RollDice => GameEvent::Roll {
|
||||
player_id: self.opponent_id,
|
||||
|
|
@ -351,7 +351,7 @@ impl TrictracEnvironment {
|
|||
calculate_points = true;
|
||||
GameEvent::RollResult {
|
||||
player_id: self.opponent_id,
|
||||
dice: store::Dice {
|
||||
dice: trictrac_store::Dice {
|
||||
values: dice_values,
|
||||
},
|
||||
}
|
||||
|
|
@ -371,7 +371,7 @@ impl TrictracEnvironment {
|
|||
}
|
||||
}
|
||||
TurnStage::MarkAdvPoints => {
|
||||
let opponent_color = store::Color::Black;
|
||||
let opponent_color = trictrac_store::Color::Black;
|
||||
let dice_roll_count = self
|
||||
.game
|
||||
.players
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::training_common;
|
|||
use burn::{prelude::Backend, tensor::Tensor};
|
||||
use burn_rl::base::{Action, Environment, Snapshot, State};
|
||||
use rand::{rng, Rng};
|
||||
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||
use trictrac_store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||
|
||||
const ERROR_REWARD: f32 = -1.0012121;
|
||||
const REWARD_RATIO: f32 = 0.1;
|
||||
|
|
@ -262,7 +262,7 @@ impl TrictracEnvironment {
|
|||
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
||||
let dice_event = GameEvent::RollResult {
|
||||
player_id: self.active_player_id,
|
||||
dice: store::Dice {
|
||||
dice: trictrac_store::Dice {
|
||||
values: dice_values,
|
||||
},
|
||||
};
|
||||
|
|
@ -310,7 +310,7 @@ impl TrictracEnvironment {
|
|||
|
||||
// Exécuter l'action selon le turn_stage
|
||||
let mut calculate_points = false;
|
||||
let opponent_color = store::Color::Black;
|
||||
let opponent_color = trictrac_store::Color::Black;
|
||||
let event = match self.game.turn_stage {
|
||||
TurnStage::RollDice => GameEvent::Roll {
|
||||
player_id: self.opponent_id,
|
||||
|
|
@ -321,7 +321,7 @@ impl TrictracEnvironment {
|
|||
calculate_points = true;
|
||||
GameEvent::RollResult {
|
||||
player_id: self.opponent_id,
|
||||
dice: store::Dice {
|
||||
dice: trictrac_store::Dice {
|
||||
values: dice_values,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use bot::burnrl::algos::{dqn, dqn_valid, ppo, ppo_valid, sac, sac_valid};
|
||||
use bot::burnrl::environment::TrictracEnvironment;
|
||||
use bot::burnrl::environment_valid::TrictracEnvironment as TrictracEnvironmentValid;
|
||||
use bot::burnrl::utils::{demo_model, Config};
|
||||
use trictrac_bot::burnrl::algos::{dqn, dqn_valid, ppo, ppo_valid, sac, sac_valid};
|
||||
use trictrac_bot::burnrl::environment::TrictracEnvironment;
|
||||
use trictrac_bot::burnrl::environment_valid::TrictracEnvironment as TrictracEnvironmentValid;
|
||||
use trictrac_bot::burnrl::utils::{demo_model, Config};
|
||||
use burn::backend::{Autodiff, NdArray};
|
||||
use burn_rl::base::ElemType;
|
||||
use std::env;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub mod training_common;
|
|||
pub mod trictrac_board;
|
||||
|
||||
use log::debug;
|
||||
use store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||
use trictrac_store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||
pub use strategy::default::DefaultStrategy;
|
||||
pub use strategy::dqnburn::DqnBurnStrategy;
|
||||
pub use strategy::erroneous_moves::ErroneousStrategy;
|
||||
|
|
@ -144,7 +144,7 @@ impl Bot {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use store::{Dice, Stage};
|
||||
use trictrac_store::{Dice, Stage};
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
||||
use store::MoveRules;
|
||||
use trictrac_store::MoveRules;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DefaultStrategy {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use burn_rl::base::{ElemType, Model, State};
|
|||
|
||||
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
||||
use log::info;
|
||||
use store::MoveRules;
|
||||
use trictrac_store::MoveRules;
|
||||
|
||||
use crate::burnrl::algos::dqn;
|
||||
use crate::burnrl::environment;
|
||||
|
|
@ -152,7 +152,7 @@ impl BotStrategy for DqnBurnStrategy {
|
|||
to1 = if fto1 < 0 { 0 } else { fto1 as usize };
|
||||
}
|
||||
|
||||
let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||
let checker_move1 = trictrac_store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||
|
||||
let mut tmp_board = self.game.board.clone();
|
||||
let move_res = tmp_board.move_checker(&self.color, checker_move1);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
||||
use rand::{prelude::IndexedRandom, rng};
|
||||
use store::MoveRules;
|
||||
use trictrac_store::MoveRules;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RandomStrategy {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::io::Read;
|
|||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use store::MoveRules;
|
||||
use trictrac_store::MoveRules;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StableBaselines3Strategy {
|
||||
|
|
@ -79,12 +79,12 @@ impl StableBaselines3Strategy {
|
|||
|
||||
// Convertir l'étape du tour en entier
|
||||
let turn_stage = match self.game.turn_stage {
|
||||
store::TurnStage::RollDice => 0,
|
||||
store::TurnStage::RollWaiting => 1,
|
||||
store::TurnStage::MarkPoints => 2,
|
||||
store::TurnStage::HoldOrGoChoice => 3,
|
||||
store::TurnStage::Move => 4,
|
||||
store::TurnStage::MarkAdvPoints => 5,
|
||||
trictrac_store::TurnStage::RollDice => 0,
|
||||
trictrac_store::TurnStage::RollWaiting => 1,
|
||||
trictrac_store::TurnStage::MarkPoints => 2,
|
||||
trictrac_store::TurnStage::HoldOrGoChoice => 3,
|
||||
trictrac_store::TurnStage::Move => 4,
|
||||
trictrac_store::TurnStage::MarkAdvPoints => 5,
|
||||
};
|
||||
|
||||
// Récupérer les points et trous des joueurs
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::cmp::{max, min};
|
|||
use std::fmt::{Debug, Display, Formatter};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use store::{CheckerMove, GameEvent, GameState};
|
||||
use trictrac_store::{CheckerMove, GameEvent, GameState};
|
||||
|
||||
// 1 (Roll) + 1 (Go) + 512 (mouvements possibles)
|
||||
// avec 512 = 2 (choix du dé) * 16 * 16 (choix de la dame 0-15 pour chaque from)
|
||||
|
|
@ -94,13 +94,13 @@ impl TrictracAction {
|
|||
(state.dice.values.1, state.dice.values.0)
|
||||
};
|
||||
|
||||
let color = &store::Color::White;
|
||||
let color = &trictrac_store::Color::White;
|
||||
let from1 = state
|
||||
.board
|
||||
.get_checker_field(color, *checker1 as u8)
|
||||
.unwrap_or(0);
|
||||
let mut to1 = from1 + dice1 as usize;
|
||||
let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||
let checker_move1 = trictrac_store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||
|
||||
let mut tmp_board = state.board.clone();
|
||||
let move_result = tmp_board.move_checker(color, checker_move1);
|
||||
|
|
@ -120,8 +120,8 @@ impl TrictracAction {
|
|||
to2 -= 1;
|
||||
}
|
||||
|
||||
let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||
let checker_move2 = store::CheckerMove::new(from2, to2).unwrap_or_default();
|
||||
let checker_move1 = trictrac_store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||
let checker_move2 = trictrac_store::CheckerMove::new(from2, to2).unwrap_or_default();
|
||||
|
||||
Some(GameEvent::Move {
|
||||
player_id: state.active_player_id,
|
||||
|
|
@ -179,8 +179,8 @@ impl TrictracAction {
|
|||
// from2,
|
||||
// } => {
|
||||
// // Effectuer un mouvement
|
||||
// let checker_move1 = store::CheckerMove::new(move1.0, move1.1).unwrap_or_default();
|
||||
// let checker_move2 = store::CheckerMove::new(move2.0, move2.1).unwrap_or_default();
|
||||
// let checker_move1 = trictrac_store::CheckerMove::new(move1.0, move1.1).unwrap_or_default();
|
||||
// let checker_move2 = trictrac_store::CheckerMove::new(move2.0, move2.1).unwrap_or_default();
|
||||
//
|
||||
// Some(GameEvent::Move {
|
||||
// player_id: self.agent_player_id,
|
||||
|
|
@ -193,7 +193,7 @@ impl TrictracAction {
|
|||
|
||||
/// Obtient les actions valides pour l'état de jeu actuel
|
||||
pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
||||
use store::TurnStage;
|
||||
use trictrac_store::TurnStage;
|
||||
|
||||
let mut valid_actions = Vec::new();
|
||||
|
||||
|
|
@ -216,11 +216,11 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
|||
valid_actions.push(TrictracAction::Go);
|
||||
|
||||
// Ajoute aussi les mouvements possibles
|
||||
let rules = store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
||||
let rules = trictrac_store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
||||
let possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
||||
|
||||
// Modififier checker_moves_to_trictrac_action si on doit gérer Black
|
||||
assert_eq!(color, store::Color::White);
|
||||
assert_eq!(color, trictrac_store::Color::White);
|
||||
for (move1, move2) in possible_moves {
|
||||
valid_actions.push(checker_moves_to_trictrac_action(
|
||||
&move1, &move2, &color, game_state,
|
||||
|
|
@ -228,7 +228,7 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
|||
}
|
||||
}
|
||||
TurnStage::Move => {
|
||||
let rules = store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
||||
let rules = trictrac_store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
||||
let mut possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
||||
if possible_moves.is_empty() {
|
||||
// Empty move
|
||||
|
|
@ -236,7 +236,7 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
|||
}
|
||||
|
||||
// Modififier checker_moves_to_trictrac_action si on doit gérer Black
|
||||
assert_eq!(color, store::Color::White);
|
||||
assert_eq!(color, trictrac_store::Color::White);
|
||||
for (move1, move2) in possible_moves {
|
||||
valid_actions.push(checker_moves_to_trictrac_action(
|
||||
&move1, &move2, &color, game_state,
|
||||
|
|
@ -256,7 +256,7 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
|||
fn checker_moves_to_trictrac_action(
|
||||
move1: &CheckerMove,
|
||||
move2: &CheckerMove,
|
||||
color: &store::Color,
|
||||
color: &trictrac_store::Color,
|
||||
state: &crate::GameState,
|
||||
) -> TrictracAction {
|
||||
let to1 = move1.get_to();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use internal_iterator::InternalIterator;
|
|||
use std::fmt;
|
||||
use std::hash::Hash;
|
||||
use std::ops::ControlFlow;
|
||||
use store::Color;
|
||||
use trictrac_store::Color;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct TrictracBoard(crate::GameState);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue