feat: python store bindings (wip)
This commit is contained in:
parent
11b75eb34d
commit
924a4f2af0
2 changed files with 15 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import trictrac_store
|
import trictrac_store
|
||||||
|
|
||||||
game = trictrac_store.TricTrac()
|
game = trictrac_store.TricTrac()
|
||||||
print(game.get_active_player_id())
|
print(game.current_player_idx())
|
||||||
print(game.get_legal_actions())
|
print(game.get_legal_actions(game.current_player_idx()))
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use crate::game::{GameEvent, GameState, Stage, TurnStage};
|
||||||
use crate::game_rules_moves::MoveRules;
|
use crate::game_rules_moves::MoveRules;
|
||||||
use crate::game_rules_points::PointsRules;
|
use crate::game_rules_points::PointsRules;
|
||||||
use crate::player::{Color, PlayerId};
|
use crate::player::{Color, PlayerId};
|
||||||
use crate::training_common::get_valid_action_indices;
|
use crate::training_common::{get_valid_action_indices, TrictracAction};
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
struct TricTrac {
|
struct TricTrac {
|
||||||
|
|
@ -50,8 +50,18 @@ impl TricTrac {
|
||||||
self.game_state.active_player_id - 1
|
self.game_state.active_player_id - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_legal_actions(&self) -> Vec<usize> {
|
fn get_legal_actions(&self, player_id: u64) -> Vec<usize> {
|
||||||
|
if player_id == self.current_player_idx() {
|
||||||
get_valid_action_indices(&self.game_state)
|
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
|
/// Lance les dés ou utilise la séquence prédéfinie
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue