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