From 924a4f2af0bb8c698371be349e1c2bb28a7762e2 Mon Sep 17 00:00:00 2001 From: Henri Bourcereau Date: Sun, 8 Feb 2026 18:57:20 +0100 Subject: [PATCH] feat: python store bindings (wip) --- bot/python/test.py | 4 ++-- store/src/pyengine.rs | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bot/python/test.py b/bot/python/test.py index fb604dd..8c4f16b 100644 --- a/bot/python/test.py +++ b/bot/python/test.py @@ -1,5 +1,5 @@ import trictrac_store game = trictrac_store.TricTrac() -print(game.get_active_player_id()) -print(game.get_legal_actions()) +print(game.current_player_idx()) +print(game.get_legal_actions(game.current_player_idx())) diff --git a/store/src/pyengine.rs b/store/src/pyengine.rs index 3a609d7..904a3cc 100644 --- a/store/src/pyengine.rs +++ b/store/src/pyengine.rs @@ -8,7 +8,7 @@ use crate::game::{GameEvent, GameState, Stage, TurnStage}; use crate::game_rules_moves::MoveRules; use crate::game_rules_points::PointsRules; use crate::player::{Color, PlayerId}; -use crate::training_common::get_valid_action_indices; +use crate::training_common::{get_valid_action_indices, TrictracAction}; #[pyclass] struct TricTrac { @@ -50,8 +50,18 @@ impl TricTrac { self.game_state.active_player_id - 1 } - fn get_legal_actions(&self) -> Vec { - get_valid_action_indices(&self.game_state) + fn get_legal_actions(&self, player_id: u64) -> Vec { + if player_id == self.current_player_idx() { + get_valid_action_indices(&self.game_state) + } else { + vec![] + } + } + + fn action_to_string(&self, player_idx: u64, action_idx: usize) -> String { + TrictracAction::from_action_index(action_idx) + .map(|a| a.to_string()) + .unwrap_or("unknown action".into()) } /// Lance les dés ou utilise la séquence prédéfinie