diff --git a/Cargo.lock b/Cargo.lock index 2ba864f..d504e2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,6 +321,7 @@ dependencies = [ "burn", "burn-rl", "env_logger 0.10.0", + "log", "pretty_assertions", "rand 0.8.5", "serde", @@ -881,6 +882,7 @@ dependencies = [ "bot", "env_logger 0.11.6", "itertools 0.13.0", + "log", "pico-args", "pretty_assertions", "renet", diff --git a/bot/Cargo.toml b/bot/Cargo.toml index 3fd08c4..a5667fa 100644 --- a/bot/Cargo.toml +++ b/bot/Cargo.toml @@ -22,3 +22,4 @@ rand = "0.8" env_logger = "0.10" burn = { version = "0.17", features = ["ndarray", "autodiff"] } burn-rl = { git = "https://github.com/yunjhongwu/burn-rl-examples.git", package = "burn-rl" } +log = "0.4.20" diff --git a/bot/src/lib.rs b/bot/src/lib.rs index c0abca7..6326253 100644 --- a/bot/src/lib.rs +++ b/bot/src/lib.rs @@ -1,6 +1,7 @@ pub mod dqn; pub mod strategy; +use log::{error, info}; use store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage}; pub use strategy::default::DefaultStrategy; pub use strategy::dqn::DqnStrategy; @@ -63,8 +64,8 @@ impl Bot { } pub fn handle_event(&mut self, event: &GameEvent) -> Option { + info!(">>>> {:?} BOT handle", self.color); let game = self.strategy.get_mut_game(); - // println!("----- before : {:?}", game); let internal_event = if self.color == Color::Black { &event.get_mirror() } else { @@ -75,6 +76,7 @@ impl Bot { let turn_stage = game.turn_stage; game.consume(internal_event); if game.stage == Stage::Ended { + info!("<<<< end {:?} BOT handle", self.color); return None; } let active_player_id = if self.color == Color::Black { @@ -89,9 +91,7 @@ impl Bot { if active_player_id == self.player_id { let player_points = game.who_plays().map(|p| (p.points, p.holes)); if self.color == Color::Black { - println!( - " input (internal) evt : {internal_event:?}, {init_player_points:?}, {turn_stage:?}" - ); + info!( " input (internal) evt : {internal_event:?}, points : {init_player_points:?}, stage : {turn_stage:?}"); } let internal_event = match game.turn_stage { TurnStage::MarkAdvPoints => Some(GameEvent::Mark { @@ -120,12 +120,15 @@ impl Bot { _ => None, }; return if self.color == Color::Black { - println!(" bot (internal) evt : {internal_event:?} - {player_points:?}"); + info!(" bot (internal) evt : {internal_event:?} ; points : {player_points:?}"); + info!("<<<< end {:?} BOT handle", self.color); internal_event.map(|evt| evt.get_mirror()) } else { + info!("<<<< end {:?} BOT handle", self.color); internal_event }; } + info!("<<<< end {:?} BOT handle", self.color); None } diff --git a/client_cli/Cargo.toml b/client_cli/Cargo.toml index 4dcd86f..6c1d4e1 100644 --- a/client_cli/Cargo.toml +++ b/client_cli/Cargo.toml @@ -15,3 +15,4 @@ store = { path = "../store" } bot = { path = "../bot" } itertools = "0.13.0" env_logger = "0.11.6" +log = "0.4.20" diff --git a/client_cli/src/game_runner.rs b/client_cli/src/game_runner.rs index b0f04b4..296c907 100644 --- a/client_cli/src/game_runner.rs +++ b/client_cli/src/game_runner.rs @@ -1,4 +1,5 @@ use bot::{Bot, BotStrategy}; +use log::{error, info}; use store::{CheckerMove, DiceRoller, GameEvent, GameState, PlayerId, TurnStage}; // Application Game @@ -62,11 +63,20 @@ impl GameRunner { return None; } let valid_event = if self.state.validate(event) { + info!( + "--------------- new valid event {event:?} (stage {:?}) -----------", + self.state.turn_stage + ); self.state.consume(event); + info!( + " --> stage {:?} ; active player points {:?}", + self.state.turn_stage, + self.state.who_plays().map(|p| p.points) + ); event } else { - println!("{}", self.state); - println!("event not valid : {:?}", event); + info!("{}", self.state); + error!("event not valid : {event:?}"); panic!("crash and burn"); &GameEvent::PlayError }; diff --git a/store/src/board.rs b/store/src/board.rs index 646e929..3e563d0 100644 --- a/store/src/board.rs +++ b/store/src/board.rs @@ -114,7 +114,7 @@ impl fmt::Display for Board { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut s = String::new(); s.push_str(&format!("{:?}", self.positions)); - write!(f, "{}", s) + write!(f, "{s}") } } @@ -132,8 +132,13 @@ impl Board { } /// Globally set pieces on board ( for tests ) - pub fn set_positions(&mut self, positions: [i8; 24]) { - self.positions = positions; + pub fn set_positions(&mut self, color: &Color, positions: [i8; 24]) { + let mut new_positions = positions; + if color == &Color::Black { + new_positions = new_positions.map(|c| 0 - c); + new_positions.reverse(); + } + self.positions = new_positions; } pub fn count_checkers(&self, color: Color, from: Field, to: Field) -> u8 { @@ -672,9 +677,12 @@ mod tests { #[test] fn is_quarter_fillable() { let mut board = Board::new(); - board.set_positions([ - 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, - ]); + board.set_positions( + &Color::White, + [ + 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, + ], + ); assert!(board.is_quarter_fillable(Color::Black, 1)); assert!(!board.is_quarter_fillable(Color::Black, 12)); assert!(board.is_quarter_fillable(Color::Black, 13)); @@ -683,25 +691,34 @@ mod tests { assert!(board.is_quarter_fillable(Color::White, 12)); assert!(!board.is_quarter_fillable(Color::White, 13)); assert!(board.is_quarter_fillable(Color::White, 24)); - board.set_positions([ - 5, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -8, 0, 0, 0, 0, 0, -5, - ]); + board.set_positions( + &Color::White, + [ + 5, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -8, 0, 0, 0, 0, 0, -5, + ], + ); assert!(board.is_quarter_fillable(Color::Black, 13)); assert!(!board.is_quarter_fillable(Color::Black, 24)); assert!(!board.is_quarter_fillable(Color::White, 1)); assert!(board.is_quarter_fillable(Color::White, 12)); - board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -12, 0, 0, 0, 0, 1, 0, - ]); + board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -12, 0, 0, 0, 0, 1, 0, + ], + ); assert!(board.is_quarter_fillable(Color::Black, 16)); } #[test] fn get_quarter_filling_candidate() { let mut board = Board::new(); - board.set_positions([ - 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + board.set_positions( + &Color::White, + [ + 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); assert_eq!(vec![2], board.get_quarter_filling_candidate(Color::White)); } } diff --git a/store/src/game.rs b/store/src/game.rs index a74cea0..c9995b8 100644 --- a/store/src/game.rs +++ b/store/src/game.rs @@ -521,13 +521,14 @@ impl GameState { self.inc_roll_count(self.active_player_id); self.turn_stage = TurnStage::MarkPoints; (self.dice_jans, self.dice_points) = self.get_rollresult_jans(dice); + info!("points from result : {:?}", self.dice_points); if !self.schools_enabled { // Schools are not enabled. We mark points automatically // the points earned by the opponent will be marked on its turn let new_hole = self.mark_points(self.active_player_id, self.dice_points.0); if new_hole { let holes_count = self.get_active_player().unwrap().holes; - println!("new hole -> {:?}", holes_count); + info!("new hole -> {holes_count:?}"); if holes_count > 12 { self.stage = Stage::Ended; } else { @@ -605,6 +606,10 @@ impl GameState { fn get_rollresult_jans(&self, dice: &Dice) -> (PossibleJans, (u8, u8)) { let player = &self.players.get(&self.active_player_id).unwrap(); + info!( + "get rollresult for {:?} {:?} {:?} (roll count {:?})", + player.color, self.board, dice, player.dice_roll_count + ); let points_rules = PointsRules::new(&player.color, &self.board, *dice); points_rules.get_result_jans(player.dice_roll_count) } @@ -647,10 +652,11 @@ impl GameState { p.points = sum_points % 12; p.holes += holes; - if points > 0 && p.holes > 15 { + // if points > 0 && p.holes > 15 { + if points > 0 { info!( - "player {:?} holes : {:?} added points : {:?}", - player_id, p.holes, points + "player {player_id:?} holes : {:?} (+{holes:?}) points : {:?} (+{points:?} - {jeux:?})", + p.holes, p.points ) } p diff --git a/store/src/game_rules_moves.rs b/store/src/game_rules_moves.rs index 17e572e..31c43fa 100644 --- a/store/src/game_rules_moves.rs +++ b/store/src/game_rules_moves.rs @@ -625,18 +625,24 @@ mod tests { #[test] fn can_take_corner_by_effect() { let mut rules = MoveRules::default(); - rules.board.set_positions([ - 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, - ]); + rules.board.set_positions( + &Color::White, + [ + 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, + ], + ); rules.dice.values = (4, 4); assert!(rules.can_take_corner_by_effect()); rules.dice.values = (5, 5); assert!(!rules.can_take_corner_by_effect()); - rules.board.set_positions([ - 10, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, - ]); + rules.board.set_positions( + &Color::White, + [ + 10, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, + ], + ); rules.dice.values = (4, 4); assert!(!rules.can_take_corner_by_effect()); } @@ -645,9 +651,12 @@ mod tests { fn prise_en_puissance() { let mut state = MoveRules::default(); // prise par puissance ok - state.board.set_positions([ - 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, - ]); + state.board.set_positions( + &Color::White, + [ + 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(8, 12).unwrap(), @@ -658,25 +667,34 @@ mod tests { assert!(state.moves_allowed(&moves).is_ok()); // opponent corner must be empty - state.board.set_positions([ - 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -13, - ]); + state.board.set_positions( + &Color::White, + [ + 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -13, + ], + ); assert!(!state.is_move_by_puissance(&moves)); assert!(!state.moves_follows_dices(&moves)); // Si on a la possibilité de prendre son coin à la fois par effet, c'est à dire naturellement, et aussi par puissance, on doit le prendre par effet - state.board.set_positions([ - 5, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, - ]); + state.board.set_positions( + &Color::White, + [ + 5, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, + ], + ); assert_eq!( Err(MoveError::CornerByEffectPossible), state.moves_allowed(&moves) ); // on a déjà pris son coin : on ne peux plus y deplacer des dames par puissance - state.board.set_positions([ - 8, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, - ]); + state.board.set_positions( + &Color::White, + [ + 8, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, + ], + ); assert!(!state.is_move_by_puissance(&moves)); assert!(!state.moves_follows_dices(&moves)); } @@ -685,9 +703,12 @@ mod tests { fn exit() { let mut state = MoveRules::default(); // exit ok - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(20, 0).unwrap(), @@ -697,9 +718,12 @@ mod tests { assert!(state.moves_allowed(&moves).is_ok()); // toutes les dames doivent être dans le jan de retour - state.board.set_positions([ - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(20, 0).unwrap(), @@ -711,9 +735,12 @@ mod tests { ); // on ne peut pas sortir une dame avec un nombre excédant si on peut en jouer une avec un nombre défaillant - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 2, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 2, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(20, 0).unwrap(), @@ -725,9 +752,12 @@ mod tests { ); // on doit jouer le nombre excédant le plus éloigné - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(20, 0).unwrap(), @@ -741,9 +771,12 @@ mod tests { assert!(state.moves_allowed(&moves).is_ok()); // Cas de la dernière dame - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(23, 0).unwrap(), @@ -756,9 +789,12 @@ mod tests { #[test] fn move_check_opponent_fillable_quarter() { let mut state = MoveRules::default(); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(11, 16).unwrap(), @@ -766,9 +802,12 @@ mod tests { ); assert!(state.moves_allowed(&moves).is_ok()); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -12, 0, 0, 0, 0, 1, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -12, 0, 0, 0, 0, 1, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(11, 16).unwrap(), @@ -779,9 +818,12 @@ mod tests { state.moves_allowed(&moves) ); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -12, 0, 0, 0, 0, 1, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -12, 0, 0, 0, 0, 1, 0, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(11, 16).unwrap(), @@ -789,9 +831,12 @@ mod tests { ); assert!(state.moves_allowed(&moves).is_ok()); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, -12, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, -12, + ], + ); state.dice.values = (5, 5); let moves = ( CheckerMove::new(11, 16).unwrap(), @@ -806,9 +851,12 @@ mod tests { #[test] fn move_check_fillable_quarter() { let mut state = MoveRules::default(); - state.board.set_positions([ - 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, + ], + ); state.dice.values = (5, 4); let moves = ( CheckerMove::new(1, 6).unwrap(), @@ -821,9 +869,12 @@ mod tests { ); assert_eq!(Err(MoveError::MustFillQuarter), state.moves_allowed(&moves)); - state.board.set_positions([ - 2, 3, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 2, 3, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 3); let moves = ( CheckerMove::new(6, 8).unwrap(), @@ -840,9 +891,12 @@ mod tests { #[test] fn move_play_all_dice() { let mut state = MoveRules::default(); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + ], + ); state.dice.values = (1, 3); let moves = ( CheckerMove::new(22, 0).unwrap(), @@ -861,9 +915,12 @@ mod tests { fn move_opponent_rest_corner_rules() { // fill with 2 checkers : forbidden let mut state = MoveRules::default(); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (1, 1); let moves = ( CheckerMove::new(12, 13).unwrap(), @@ -891,9 +948,12 @@ mod tests { fn move_rest_corner_enter() { // direct let mut state = MoveRules::default(); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); let moves = ( CheckerMove::new(10, 12).unwrap(), @@ -915,9 +975,12 @@ mod tests { #[test] fn move_rest_corner_blocked() { let mut state = MoveRules::default(); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); let moves = ( CheckerMove::new(0, 0).unwrap(), @@ -926,9 +989,12 @@ mod tests { assert!(state.moves_follows_dices(&moves)); assert!(state.moves_allowed(&moves).is_ok()); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + ], + ); state.dice.values = (2, 1); let moves = ( CheckerMove::new(23, 24).unwrap(), @@ -949,9 +1015,12 @@ mod tests { #[test] fn move_rest_corner_exit() { let mut state = MoveRules::default(); - state.board.set_positions([ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 3); let moves = ( CheckerMove::new(12, 14).unwrap(), @@ -967,9 +1036,12 @@ mod tests { fn move_rest_corner_toutdune() { let mut state = MoveRules::default(); // We can't go to the occupied rest corner as an intermediary step - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); let moves = ( CheckerMove::new(11, 13).unwrap(), @@ -978,9 +1050,12 @@ mod tests { assert!(!state.moves_possible(&moves)); // We can use the empty rest corner as an intermediary step - state.board.set_positions([ - 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, -2, -2, -2, -3, - ]); + state.board.set_positions( + &Color::White, + [ + 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, -2, -2, -2, -3, + ], + ); state.dice.values = (6, 5); let moves = ( CheckerMove::new(8, 13).unwrap(), @@ -994,9 +1069,12 @@ mod tests { #[test] fn move_play_stronger_dice() { let mut state = MoveRules::default(); - state.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 3); let moves = ( CheckerMove::new(12, 14).unwrap(), @@ -1034,9 +1112,12 @@ mod tests { assert!(!state.moves_possible(&moves)); // Can't move the same checker twice - state.board.set_positions([ - 3, 3, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 3, 3, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); let moves = ( CheckerMove::new(3, 5).unwrap(), @@ -1056,9 +1137,12 @@ mod tests { #[test] fn filling_moves_sequences() { let mut state = MoveRules::default(); - state.board.set_positions([ - 3, 3, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 3, 3, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); let filling_moves_sequences = state.get_quarter_filling_moves_sequences(); // println!( @@ -1067,17 +1151,23 @@ mod tests { // ); assert_eq!(2, filling_moves_sequences.len()); - state.board.set_positions([ - 3, 2, 3, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 3, 2, 3, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 2); let filling_moves_sequences = state.get_quarter_filling_moves_sequences(); // println!("{:?}", filling_moves_sequences); assert_eq!(2, filling_moves_sequences.len()); - state.board.set_positions([ - 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); let filling_moves_sequences = state.get_quarter_filling_moves_sequences(); // println!( @@ -1087,9 +1177,12 @@ mod tests { assert_eq!(2, filling_moves_sequences.len()); // positions - state.board.set_positions([ - 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, -2, -2, -2, -3, - ]); + state.board.set_positions( + &Color::White, + [ + 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, -2, -2, -2, -3, + ], + ); state.dice.values = (6, 5); let filling_moves_sequences = state.get_quarter_filling_moves_sequences(); assert_eq!(1, filling_moves_sequences.len()); @@ -1099,19 +1192,46 @@ mod tests { fn scoring_filling_moves_sequences() { let mut state = MoveRules::default(); - state.board.set_positions([ - 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); assert_eq!(1, state.get_scoring_quarter_filling_moves_sequences().len()); - state.board.set_positions([ - 2, 3, 3, 3, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 2, 3, 3, 3, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 1); let filling_moves_sequences = state.get_scoring_quarter_filling_moves_sequences(); // println!("{:?}", filling_moves_sequences); assert_eq!(3, filling_moves_sequences.len()); + + // preserve filling + state.board.set_positions( + &Color::White, + [ + 2, 2, 2, 2, 2, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, -1, -2, -3, -5, 0, -1, + ], + ); + state.dice.values = (3, 1); + assert_eq!(1, state.get_scoring_quarter_filling_moves_sequences().len()); + + // preserve filling (black) + let mut state = MoveRules::new(&Color::Black, &Board::default(), Dice::default()); + state.board.set_positions( + &Color::Black, + [ + 1, 0, 5, 3, 2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -4, -2, -2, -2, -2, -2, + ], + ); + state.dice.values = (3, 1); + assert_eq!(1, state.get_scoring_quarter_filling_moves_sequences().len()); } // prise de coin par puissance et conservation de jan #18 @@ -1120,9 +1240,12 @@ mod tests { fn corner_by_effect_and_filled_corner() { let mut state = MoveRules::default(); - state.board.set_positions([ - 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, -2, -2, -2, -3, - ]); + state.board.set_positions( + &Color::White, + [ + 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, -2, 0, 0, 0, -2, 0, -2, -2, -2, -2, -3, + ], + ); state.dice.values = (6, 5); let moves = ( @@ -1155,9 +1278,12 @@ mod tests { fn get_possible_moves_sequences() { let mut state = MoveRules::default(); - state.board.set_positions([ - 2, 0, -2, -2, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + state.board.set_positions( + &Color::White, + [ + 2, 0, -2, -2, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); state.dice.values = (2, 3); let moves = ( CheckerMove::new(9, 11).unwrap(), diff --git a/store/src/game_rules_points.rs b/store/src/game_rules_points.rs index 8656b54..24991eb 100644 --- a/store/src/game_rules_points.rs +++ b/store/src/game_rules_points.rs @@ -5,6 +5,7 @@ use crate::player::Color; use crate::CheckerMove; use crate::Error; +use log::info; use serde::{Deserialize, Serialize}; use std::cmp; use std::collections::HashMap; @@ -158,9 +159,9 @@ impl PointsRules { self.move_rules.dice = dice; } - pub fn update_positions(&mut self, positions: [i8; 24]) { - self.board.set_positions(positions); - self.move_rules.board.set_positions(positions); + pub fn update_positions(&mut self, color: &Color, positions: [i8; 24]) { + self.board.set_positions(color, positions); + self.move_rules.board.set_positions(color, positions); } fn get_jans(&self, board_ini: &Board, dice_rolls_count: u8) -> PossibleJans { @@ -381,6 +382,7 @@ impl PointsRules { pub fn get_result_jans(&self, dice_rolls_count: u8) -> (PossibleJans, (u8, u8)) { let jans = self.get_jans(&self.board, dice_rolls_count); + info!("jans : {jans:?}"); let points_jans = jans.clone(); (jans, self.get_jans_points(points_jans)) } @@ -481,9 +483,12 @@ mod tests { #[test] fn get_jans_by_dice_order() { let mut rules = PointsRules::default(); - rules.board.set_positions([ - 2, 0, -1, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 2, 0, -1, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); let jans = get_jans_by_ordered_dice(&rules.board, &[2, 3], None, false); assert_eq!(1, jans.len()); @@ -495,9 +500,12 @@ mod tests { // On peut passer par une dame battue pour battre une autre dame // mais pas par une case remplie par l'adversaire - rules.board.set_positions([ - 2, 0, -1, -2, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 2, 0, -1, -2, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); let mut jans = get_jans_by_ordered_dice(&rules.board, &[2, 3], None, false); let jans_revert_dices = get_jans_by_ordered_dice(&rules.board, &[3, 2], None, false); @@ -506,25 +514,34 @@ mod tests { jans.merge(jans_revert_dices); assert_eq!(2, jans.get(&Jan::TrueHitSmallJan).unwrap().len()); - rules.board.set_positions([ - 2, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 2, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); let jans = get_jans_by_ordered_dice(&rules.board, &[2, 3], None, false); assert_eq!(1, jans.len()); assert_eq!(2, jans.get(&Jan::TrueHitSmallJan).unwrap().len()); - rules.board.set_positions([ - 2, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 2, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); let jans = get_jans_by_ordered_dice(&rules.board, &[2, 3], None, false); assert_eq!(1, jans.len()); assert_eq!(1, jans.get(&Jan::TrueHitSmallJan).unwrap().len()); - rules.board.set_positions([ - 2, 0, 1, 1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 2, 0, 1, 1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); let jans = get_jans_by_ordered_dice(&rules.board, &[2, 3], None, false); assert_eq!(1, jans.len()); @@ -533,25 +550,34 @@ mod tests { // corners handling // deux dés bloqués (coin de repos et coin de l'adversaire) - rules.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); // le premier dé traité est le dernier du vecteur : 1 let jans = get_jans_by_ordered_dice(&rules.board, &[2, 1], None, false); // println!("jans (dés bloqués) : {:?}", jans.get(&Jan::TrueHit)); assert_eq!(0, jans.len()); // dé dans son coin de repos : peut tout de même battre à vrai - rules.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); let jans = get_jans_by_ordered_dice(&rules.board, &[3, 3], None, false); assert_eq!(1, jans.len()); // premier dé bloqué, mais tout d'une possible en commençant par le second - rules.board.set_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); let mut jans = get_jans_by_ordered_dice(&rules.board, &[3, 1], None, false); let jans_revert_dices = get_jans_by_ordered_dice(&rules.board, &[1, 3], None, false); assert_eq!(1, jans_revert_dices.len()); @@ -569,169 +595,274 @@ mod tests { // ----- Jan de récompense // Battre à vrai une dame située dans la table des petits jans : 4 + 4 + 4 = 12 let mut rules = PointsRules::default(); - rules.update_positions([ - 2, 0, -1, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 2, 0, -1, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 3) }); assert_eq!(12, rules.get_points(5).0); + // Calcul des points pour noir + let mut board = Board::new(); + board.set_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, -2, + ], + ); + let mut rules = PointsRules::new(&Color::Black, &board, Dice { values: (2, 3) }); + assert_eq!(12, rules.get_points(5).0); + // Battre à vrai une dame située dans la table des grands jans : 2 + 2 = 4 let mut rules = PointsRules::default(); - rules.update_positions([ - 2, 0, 0, -1, 2, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 2, 0, 0, -1, 2, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 4) }); assert_eq!(4, rules.get_points(5).0); // Battre à vrai une dame située dans la table des grands jans : 2 let mut rules = PointsRules::default(); - rules.update_positions([ - 2, 0, -2, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 2, 0, -2, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 4) }); assert_eq!((2, 2), rules.get_points(5)); // Battre à vrai le coin adverse par doublet : 6 - rules.update_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 2) }); assert_eq!(6, rules.get_points(5).0); // Cas de battage du coin de repos adverse impossible - rules.update_positions([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (1, 1) }); assert_eq!(0, rules.get_points(5).0); // ---- Jan de remplissage // Faire un petit jan : 4 - rules.update_positions([ - 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 3, 1, 2, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 1) }); assert_eq!(1, rules.get_jans(&rules.board, 5).len()); assert_eq!(4, rules.get_points(5).0); // Faire un petit jan avec un doublet : 6 - rules.update_positions([ - 2, 3, 1, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 2, 3, 1, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (1, 1) }); assert_eq!(6, rules.get_points(5).0); // Faire un petit jan avec 2 moyens : 6 + 6 = 12 - rules.update_positions([ - 3, 3, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 3, 3, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (1, 1) }); assert_eq!(12, rules.get_points(5).0); // Conserver un jan avec un doublet : 6 - rules.update_positions([ - 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (1, 1) }); assert_eq!(6, rules.get_points(5).0); + // Conserver un jan + rules.update_positions( + &Color::White, + [ + 2, 2, 2, 2, 2, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, -1, -2, -3, -5, 0, -1, + ], + ); + rules.set_dice(Dice { values: (3, 1) }); + assert_eq!((4, 0), rules.get_points(8)); + + // Conserver un jan (black) + let mut board = Board::new(); + board.set_positions( + &Color::Black, + [ + 1, 0, 5, 3, 2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -4, -2, -2, -2, -2, -2, + ], + ); + let rules = PointsRules::new(&Color::Black, &board, Dice { values: (3, 1) }); + assert_eq!((4, 0), rules.get_points(8)); + // ---- Sorties // Sortir toutes ses dames avant l'adversaire (simple) - rules.update_positions([ - 0, 0, -2, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, - ]); + let mut rules = PointsRules::default(); + rules.update_positions( + &Color::White, + [ + 0, 0, -2, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + ], + ); rules.set_dice(Dice { values: (3, 1) }); assert_eq!(4, rules.get_points(5).0); // Sortir toutes ses dames avant l'adversaire (doublet) - rules.update_positions([ - 0, 0, -2, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 0, 0, -2, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + ], + ); rules.set_dice(Dice { values: (2, 2) }); assert_eq!(6, rules.get_points(5).0); // ---- JANS RARES // Jan de six tables - rules.update_positions([ - 10, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 10, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (2, 3) }); assert_eq!(0, rules.get_points(5).0); - rules.update_positions([ - 10, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 10, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (2, 3) }); assert_eq!(4, rules.get_points(3).0); - rules.update_positions([ - 10, 1, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 10, 1, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (2, 3) }); assert_eq!(0, rules.get_points(3).0); - rules.update_positions([ - 10, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 10, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (2, 3) }); assert_eq!(0, rules.get_points(3).0); // Jan de deux tables - rules.update_positions([ - 13, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 13, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (2, 2) }); assert_eq!(6, rules.get_points(5).0); - rules.update_positions([ - 12, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 12, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (2, 2) }); assert_eq!(0, rules.get_points(5).0); // Contre jan de deux tables - rules.update_positions([ - 13, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 13, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (2, 2) }); assert_eq!((0, 6), rules.get_points(5)); // Jan de mézéas - rules.update_positions([ - 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (1, 1) }); assert_eq!(6, rules.get_points(5).0); - rules.update_positions([ - 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (1, 2) }); assert_eq!(4, rules.get_points(5).0); // Contre jan de mézéas - rules.update_positions([ - 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, - ]); + rules.update_positions( + &Color::White, + [ + 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, + ], + ); rules.set_dice(Dice { values: (1, 1) }); assert_eq!((0, 6), rules.get_points(5)); // ---- JANS QUI NE PEUT // Battre à faux une dame située dans la table des petits jans let mut rules = PointsRules::default(); - rules.update_positions([ - 2, 0, -2, -2, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 2, 0, -2, -2, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 3) }); assert_eq!((0, 4), rules.get_points(5)); // Battre à faux une dame située dans la table des grands jans let mut rules = PointsRules::default(); - rules.update_positions([ - 2, 0, -2, -1, -2, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 2, 0, -2, -1, -2, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 4) }); assert_eq!((0, 2), rules.get_points(5)); // Pour chaque dé non jouable (dame impuissante) let mut rules = PointsRules::default(); - rules.update_positions([ - 2, 0, -2, -2, -2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + rules.update_positions( + &Color::White, + [ + 2, 0, -2, -2, -2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ], + ); rules.set_dice(Dice { values: (2, 4) }); assert_eq!((0, 4), rules.get_points(5)); }