Compare commits

..

2 commits

Author SHA1 Message Date
1861494048 fix(cxxengine): catch errors 2026-03-02 16:10:30 +01:00
4ea4b1249b refact: comments 2026-03-02 14:48:23 +01:00
2 changed files with 12 additions and 8 deletions

View file

@ -98,7 +98,9 @@ pub fn new_trictrac_engine() -> Box<TricTracEngine> {
let mut game_state = GameState::new(false); // schools_enabled = false
game_state.init_player("player1");
game_state.init_player("player2");
game_state.consume(&GameEvent::BeginGame { goes_first: 1 });
game_state
.consume(&GameEvent::BeginGame { goes_first: 1 })
.expect("BeginGame failed during engine initialization");
Box::new(TricTracEngine { game_state })
}
@ -189,7 +191,8 @@ impl TricTracEngine {
values: (dice.die1, dice.die2),
};
self.game_state
.consume(&GameEvent::RollResult { player_id, dice });
.consume(&GameEvent::RollResult { player_id, dice })
.map_err(|e| anyhow::anyhow!(e))?;
Ok(())
}
@ -208,7 +211,9 @@ impl TricTracEngine {
match event {
Some(evt) if self.game_state.validate(&evt) => {
self.game_state.consume(&evt);
self.game_state
.consume(&evt)
.map_err(|e| anyhow::anyhow!(e))?;
Ok(())
}
Some(evt) => anyhow::bail!(

View file

@ -343,7 +343,7 @@ impl MoveRules {
return Err(MoveError::ExitByEffectPossible);
}
// - la dame choisie doit être la plus éloignée de la sortie
// The chosen checker must be the farthest from exit
// For chained moves (tout d'une), we need to check the board state AFTER the first move
let board_to_check = if moves.0.get_to() == moves.1.get_from() {
// Chained move: apply first move to get the board state
@ -367,9 +367,8 @@ impl MoveRules {
if has_filled_quarter {
// When a quarter is filled, we can only exit from fields with >2 checkers
// Find the farthest field with >2 checkers (removing one won't break the quarter)
let mut available_checkers: Vec<_> = checkers.iter()
.filter(|(_, count)| *count > 2)
.collect();
let mut available_checkers: Vec<_> =
checkers.iter().filter(|(_, count)| *count > 2).collect();
if !available_checkers.is_empty() {
// Use the farthest available checker (that won't break the quarter)
@ -409,7 +408,7 @@ impl MoveRules {
}
}
// s'il reste au moins deux dames, on vérifie que les plus éloignées soint choisies
// s'il reste au moins deux dames, on vérifie que les plus éloignées soient choisies
if has_two_checkers || has_filled_quarter {
if moves.0.get_to() == 0 && moves.1.get_to() == 0 {
// Deux coups sortants en excédant