Compare commits

..

No commits in common. "18614940485afa80c0f761ae2c62d1048f249ba9" and "f4049f548e74dd59a3da689aac97cab37fcda6b0" have entirely different histories.

2 changed files with 8 additions and 12 deletions

View file

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

View file

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