fix validations & client_cli

This commit is contained in:
Henri Bourcereau 2025-08-16 17:25:29 +02:00
parent c1e99a5f35
commit 47a8502b63
4 changed files with 18 additions and 15 deletions

View file

@ -171,6 +171,7 @@ impl Environment for TrictracEnvironment {
let mut has_played = false; let mut has_played = false;
if self.game.active_player_id == self.active_player_id { if self.game.active_player_id == self.active_player_id {
if let Some(action) = trictrac_action { if let Some(action) = trictrac_action {
let str_action = format!("{action:?}");
(reward, is_rollpoint) = self.execute_action(action); (reward, is_rollpoint) = self.execute_action(action);
if is_rollpoint { if is_rollpoint {
self.pointrolls_count += 1; self.pointrolls_count += 1;
@ -178,6 +179,7 @@ impl Environment for TrictracEnvironment {
if reward != Self::ERROR_REWARD { if reward != Self::ERROR_REWARD {
has_played = true; has_played = true;
self.goodmoves_count += 1; self.goodmoves_count += 1;
// println!("{str_action}");
} }
} else { } else {
// Action non convertible, pénalité // Action non convertible, pénalité
@ -186,14 +188,8 @@ impl Environment for TrictracEnvironment {
} }
// Faire jouer l'adversaire (stratégie simple) // Faire jouer l'adversaire (stratégie simple)
if has_played {
if self.goodmoves_count > 10 {
println!("{:?}", self.game.history);
panic!("end debug");
}
}
while self.game.active_player_id == self.opponent_id && self.game.stage != Stage::Ended { while self.game.active_player_id == self.opponent_id && self.game.stage != Stage::Ended {
print!(":"); // print!(":");
reward += self.play_opponent_if_needed(); reward += self.play_opponent_if_needed();
} }
@ -343,7 +339,7 @@ impl TrictracEnvironment {
values: dice_values, values: dice_values,
}, },
}; };
print!("o"); // print!("o");
if self.game.validate(&dice_event) { if self.game.validate(&dice_event) {
self.game.consume(&dice_event); self.game.consume(&dice_event);
let (points, adv_points) = self.game.dice_points; let (points, adv_points) = self.game.dice_points;
@ -368,7 +364,7 @@ impl TrictracEnvironment {
/// Fait jouer l'adversaire avec une stratégie simple /// Fait jouer l'adversaire avec une stratégie simple
fn play_opponent_if_needed(&mut self) -> f32 { fn play_opponent_if_needed(&mut self) -> f32 {
print!("z?"); // print!("z?");
let mut reward = 0.0; let mut reward = 0.0;
// Si c'est le tour de l'adversaire, jouer automatiquement // Si c'est le tour de l'adversaire, jouer automatiquement
@ -445,9 +441,9 @@ impl TrictracEnvironment {
if self.game.validate(&event) { if self.game.validate(&event) {
self.game.consume(&event); self.game.consume(&event);
print!("."); // print!(".");
if calculate_points { if calculate_points {
print!("x"); // print!("x");
let dice_roll_count = self let dice_roll_count = self
.game .game
.players .players

View file

@ -117,10 +117,14 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
if let Some(color) = player_color { if let Some(color) = player_color {
match game_state.turn_stage { match game_state.turn_stage {
TurnStage::RollDice | TurnStage::RollWaiting => { TurnStage::RollDice => {
valid_actions.push(TrictracAction::Roll); valid_actions.push(TrictracAction::Roll);
} }
TurnStage::MarkPoints | TurnStage::MarkAdvPoints => { TurnStage::MarkPoints | TurnStage::MarkAdvPoints | TurnStage::RollWaiting => {
panic!(
"get_valid_actions not implemented for turn stage {:?}",
game_state.turn_stage
);
// valid_actions.push(TrictracAction::Mark); // valid_actions.push(TrictracAction::Mark);
} }
TurnStage::HoldOrGoChoice => { TurnStage::HoldOrGoChoice => {

View file

@ -139,6 +139,9 @@ impl App {
// &self.game.state.board, // &self.game.state.board,
// dice, // dice,
// ); // );
self.game.handle_event(&GameEvent::Roll {
player_id: self.game.player_id.unwrap(),
});
self.game.handle_event(&GameEvent::RollResult { self.game.handle_event(&GameEvent::RollResult {
player_id: self.game.player_id.unwrap(), player_id: self.game.player_id.unwrap(),
dice, dice,

View file

@ -348,7 +348,7 @@ impl GameState {
return false; return false;
} }
// Check the turn stage // Check the turn stage
if self.turn_stage != TurnStage::RollWaiting { if self.turn_stage != TurnStage::RollDice {
error!("bad stage {:?}", self.turn_stage); error!("bad stage {:?}", self.turn_stage);
return false; return false;
} }
@ -363,7 +363,7 @@ impl GameState {
return false; return false;
} }
// Check the turn stage // Check the turn stage
if self.turn_stage != TurnStage::RollDice { if self.turn_stage != TurnStage::RollWaiting {
error!("bad stage {:?}", self.turn_stage); error!("bad stage {:?}", self.turn_stage);
return false; return false;
} }