fix: convert_action from_action_index

This commit is contained in:
Henri Bourcereau 2025-07-25 17:26:02 +02:00
parent 1e18b784d1
commit b92c9eb7ff
4 changed files with 139 additions and 4 deletions

View file

@ -92,6 +92,7 @@ impl Environment for TrictracEnvironment {
type RewardType = f32;
const MAX_STEPS: usize = 1000; // Limite max pour éviter les parties infinies
// const MAX_STEPS: usize = 5; // Limite max pour éviter les parties infinies
fn new(visualized: bool) -> Self {
let mut game = GameState::new(false);
@ -139,6 +140,7 @@ impl Environment for TrictracEnvironment {
// Convertir l'action burn-rl vers une action Trictrac
let trictrac_action = self.convert_action(action, &self.game);
// println!("chosen action: {:?} -> {:?}", action, trictrac_action);
let mut reward = 0.0;
let mut terminated = false;
@ -204,6 +206,15 @@ impl TrictracEnvironment {
&self,
action: TrictracAction,
game_state: &GameState,
) -> Option<dqn_common::TrictracAction> {
dqn_common::TrictracAction::from_action_index(action.index.try_into().unwrap())
}
/// Convertit l'index d'une action au sein des actions valides vers une action Trictrac
fn convert_valid_action_index(
&self,
action: TrictracAction,
game_state: &GameState,
) -> Option<dqn_common::TrictracAction> {
use dqn_common::get_valid_actions;