wip bot mirror
This commit is contained in:
parent
fa9c02084a
commit
12004ec4f3
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;
|
||||||
|
|
@ -26,7 +27,7 @@ pub trait BotStrategy: std::fmt::Debug {
|
||||||
pub struct Bot {
|
pub struct Bot {
|
||||||
pub player_id: PlayerId,
|
pub player_id: PlayerId,
|
||||||
strategy: Box<dyn BotStrategy>,
|
strategy: Box<dyn BotStrategy>,
|
||||||
// color: Color,
|
color: Color,
|
||||||
// schools_enabled: bool,
|
// schools_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,9 +35,9 @@ impl Default for Bot {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let strategy = DefaultStrategy::default();
|
let strategy = DefaultStrategy::default();
|
||||||
Self {
|
Self {
|
||||||
player_id: 2,
|
player_id: 1,
|
||||||
strategy: Box::new(strategy),
|
strategy: Box::new(strategy),
|
||||||
// color: Color::Black,
|
color: Color::White,
|
||||||
// schools_enabled: false,
|
// schools_enabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,57 +53,86 @@ impl Bot {
|
||||||
Color::White => 1,
|
Color::White => 1,
|
||||||
Color::Black => 2,
|
Color::Black => 2,
|
||||||
};
|
};
|
||||||
strategy.set_player_id(player_id);
|
// strategy.set_player_id(player_id);
|
||||||
strategy.set_color(color);
|
// strategy.set_color(color);
|
||||||
Self {
|
Self {
|
||||||
player_id,
|
player_id,
|
||||||
strategy,
|
strategy,
|
||||||
// color,
|
color,
|
||||||
// schools_enabled: false,
|
// schools_enabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
game.consume(event);
|
let internal_event = if self.color == Color::Black {
|
||||||
|
&event.get_mirror()
|
||||||
|
} else {
|
||||||
|
event
|
||||||
|
};
|
||||||
|
|
||||||
|
let init_player_points = game.who_plays().map(|p| (p.points, p.holes));
|
||||||
|
let turn_stage = game.turn_stage;
|
||||||
|
game.consume(internal_event);
|
||||||
if game.stage == Stage::Ended {
|
if game.stage == Stage::Ended {
|
||||||
|
info!("<<<< end {:?} BOT handle", self.color);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
if game.active_player_id == self.player_id {
|
let active_player_id = if self.color == Color::Black {
|
||||||
return match game.turn_stage {
|
if game.active_player_id == 1 {
|
||||||
|
2
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
game.active_player_id
|
||||||
|
};
|
||||||
|
if active_player_id == self.player_id {
|
||||||
|
let player_points = game.who_plays().map(|p| (p.points, p.holes));
|
||||||
|
if self.color == Color::Black {
|
||||||
|
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 {
|
TurnStage::MarkAdvPoints => Some(GameEvent::Mark {
|
||||||
player_id: self.player_id,
|
player_id: 1,
|
||||||
points: self.strategy.calculate_adv_points(),
|
points: self.strategy.calculate_adv_points(),
|
||||||
}),
|
}),
|
||||||
TurnStage::RollDice => Some(GameEvent::Roll {
|
TurnStage::RollDice => Some(GameEvent::Roll { player_id: 1 }),
|
||||||
player_id: self.player_id,
|
|
||||||
}),
|
|
||||||
TurnStage::MarkPoints => Some(GameEvent::Mark {
|
TurnStage::MarkPoints => Some(GameEvent::Mark {
|
||||||
player_id: self.player_id,
|
player_id: 1,
|
||||||
points: self.strategy.calculate_points(),
|
points: self.strategy.calculate_points(),
|
||||||
}),
|
}),
|
||||||
TurnStage::Move => Some(GameEvent::Move {
|
TurnStage::Move => Some(GameEvent::Move {
|
||||||
player_id: self.player_id,
|
player_id: 1,
|
||||||
moves: self.strategy.choose_move(),
|
moves: self.strategy.choose_move(),
|
||||||
}),
|
}),
|
||||||
TurnStage::HoldOrGoChoice => {
|
TurnStage::HoldOrGoChoice => {
|
||||||
if self.strategy.choose_go() {
|
if self.strategy.choose_go() {
|
||||||
Some(GameEvent::Go {
|
Some(GameEvent::Go { player_id: 1 })
|
||||||
player_id: self.player_id,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
Some(GameEvent::Move {
|
Some(GameEvent::Move {
|
||||||
player_id: self.player_id,
|
player_id: 1,
|
||||||
moves: self.strategy.choose_move(),
|
moves: self.strategy.choose_move(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
return if self.color == Color::Black {
|
||||||
|
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
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only used in tests below
|
||||||
pub fn get_state(&self) -> &GameState {
|
pub fn get_state(&self) -> &GameState {
|
||||||
self.strategy.get_game()
|
self.strategy.get_game()
|
||||||
}
|
}
|
||||||
|
|
@ -121,17 +151,31 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_consume() {
|
fn test_handle_event() {
|
||||||
let mut bot = Bot::new(Box::new(DefaultStrategy::default()), Color::Black);
|
let mut bot = Bot::new(Box::new(DefaultStrategy::default()), Color::Black);
|
||||||
// let mut bot = Bot::new(Box::new(DefaultStrategy::default()), Color::Black, false);
|
// let mut bot = Bot::new(Box::new(DefaultStrategy::default()), Color::Black, false);
|
||||||
let mut event = bot.handle_event(&GameEvent::BeginGame { goes_first: 2 });
|
let mut event = bot.handle_event(&GameEvent::BeginGame { goes_first: 2 });
|
||||||
assert_eq!(event, Some(GameEvent::Roll { player_id: 2 }));
|
assert_eq!(event, Some(GameEvent::Roll { player_id: 2 }));
|
||||||
assert_eq!(bot.get_state().active_player_id, 2);
|
assert_eq!(bot.get_state().active_player_id, 1); // bot internal active_player_id for black
|
||||||
|
event = bot.handle_event(&GameEvent::RollResult {
|
||||||
|
player_id: 2,
|
||||||
|
dice: Dice { values: (2, 3) },
|
||||||
|
});
|
||||||
|
assert_eq!(
|
||||||
|
event,
|
||||||
|
Some(GameEvent::Move {
|
||||||
|
player_id: 2,
|
||||||
|
moves: (
|
||||||
|
CheckerMove::new(24, 21).unwrap(),
|
||||||
|
CheckerMove::new(24, 22).unwrap()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
event = bot.handle_event(&GameEvent::BeginGame { goes_first: 1 });
|
event = bot.handle_event(&GameEvent::BeginGame { goes_first: 1 });
|
||||||
assert_eq!(event, None);
|
assert_eq!(event, None);
|
||||||
|
|
||||||
assert_eq!(bot.get_state().active_player_id, 1);
|
assert_eq!(bot.get_state().active_player_id, 2); //internal active_player_id
|
||||||
bot.handle_event(&GameEvent::RollResult {
|
bot.handle_event(&GameEvent::RollResult {
|
||||||
player_id: 1,
|
player_id: 1,
|
||||||
dice: Dice { values: (2, 3) },
|
dice: Dice { values: (2, 3) },
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ impl Default for DefaultStrategy {
|
||||||
let game = GameState::default();
|
let game = GameState::default();
|
||||||
Self {
|
Self {
|
||||||
game,
|
game,
|
||||||
player_id: 2,
|
player_id: 1,
|
||||||
color: Color::Black,
|
color: Color::White,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,21 @@ 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");
|
||||||
&GameEvent::PlayError
|
&GameEvent::PlayError
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
4
justfile
4
justfile
|
|
@ -9,8 +9,8 @@ shell:
|
||||||
runcli:
|
runcli:
|
||||||
RUST_LOG=info cargo run --bin=client_cli
|
RUST_LOG=info cargo run --bin=client_cli
|
||||||
runclibots:
|
runclibots:
|
||||||
#RUST_LOG=info cargo run --bin=client_cli -- --bot dqn,dummy
|
RUST_LOG=info cargo run --bin=client_cli -- --bot dqn,dummy
|
||||||
RUST_LOG=info cargo run --bin=client_cli -- --bot dummy,dqn
|
# RUST_LOG=info cargo run --bin=client_cli -- --bot dummy,dqn
|
||||||
match:
|
match:
|
||||||
cargo build --release --bin=client_cli
|
cargo build --release --bin=client_cli
|
||||||
LD_LIBRARY_PATH=./target/release ./target/release/client_cli -- --bot dummy,dqn
|
LD_LIBRARY_PATH=./target/release ./target/release/client_cli -- --bot dummy,dqn
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,8 @@ impl fmt::Display for GameState {
|
||||||
s.push_str(&format!("Dice: {:?}\n", self.dice));
|
s.push_str(&format!("Dice: {:?}\n", self.dice));
|
||||||
// s.push_str(&format!("Who plays: {}\n", self.who_plays().map(|player| &player.name ).unwrap_or("")));
|
// s.push_str(&format!("Who plays: {}\n", self.who_plays().map(|player| &player.name ).unwrap_or("")));
|
||||||
s.push_str(&format!("Board: {:?}\n", self.board));
|
s.push_str(&format!("Board: {:?}\n", self.board));
|
||||||
write!(f, "{}", s)
|
// s.push_str(&format!("History: {:?}\n", self.history));
|
||||||
|
write!(f, "{s}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,22 +373,30 @@ impl GameState {
|
||||||
}
|
}
|
||||||
Go { player_id } => {
|
Go { player_id } => {
|
||||||
if !self.players.contains_key(player_id) {
|
if !self.players.contains_key(player_id) {
|
||||||
error!("Player {} unknown", player_id);
|
error!("Player {player_id} unknown");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check player is currently the one making their move
|
// Check player is currently the one making their move
|
||||||
if self.active_player_id != *player_id {
|
if self.active_player_id != *player_id {
|
||||||
|
error!("Player not active : {}", self.active_player_id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check the player can leave (ie the game is in the KeepOrLeaveChoice stage)
|
// Check the player can leave (ie the game is in the KeepOrLeaveChoice stage)
|
||||||
if self.turn_stage != TurnStage::HoldOrGoChoice {
|
if self.turn_stage != TurnStage::HoldOrGoChoice {
|
||||||
|
error!("bad stage {:?}", self.turn_stage);
|
||||||
|
error!(
|
||||||
|
"black player points : {:?}",
|
||||||
|
self.get_black_player()
|
||||||
|
.map(|player| (player.points, player.holes))
|
||||||
|
);
|
||||||
|
// error!("history {:?}", self.history);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Move { player_id, moves } => {
|
Move { player_id, moves } => {
|
||||||
// Check player exists
|
// Check player exists
|
||||||
if !self.players.contains_key(player_id) {
|
if !self.players.contains_key(player_id) {
|
||||||
error!("Player {} unknown", player_id);
|
error!("Player {player_id} unknown");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check player is currently the one making their move
|
// Check player is currently the one making their move
|
||||||
|
|
@ -512,12 +521,15 @@ 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 {
|
||||||
if self.get_active_player().unwrap().holes > 12 {
|
let holes_count = self.get_active_player().unwrap().holes;
|
||||||
|
info!("new hole -> {holes_count:?}");
|
||||||
|
if holes_count > 12 {
|
||||||
self.stage = Stage::Ended;
|
self.stage = Stage::Ended;
|
||||||
} else {
|
} else {
|
||||||
self.turn_stage = TurnStage::HoldOrGoChoice;
|
self.turn_stage = TurnStage::HoldOrGoChoice;
|
||||||
|
|
@ -594,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)
|
||||||
}
|
}
|
||||||
|
|
@ -636,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
|
||||||
|
|
@ -733,6 +750,58 @@ impl GameEvent {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_mirror(&self) -> Self {
|
||||||
|
// let mut mirror = self.clone();
|
||||||
|
let mirror_player_id = if let Some(player_id) = self.player_id() {
|
||||||
|
if player_id == 1 {
|
||||||
|
2
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Self::PlayerJoined { player_id: _, name } => Self::PlayerJoined {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
name: name.clone(),
|
||||||
|
},
|
||||||
|
Self::PlayerDisconnected { player_id: _ } => GameEvent::PlayerDisconnected {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
},
|
||||||
|
Self::Roll { player_id: _ } => GameEvent::Roll {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
},
|
||||||
|
Self::RollResult { player_id: _, dice } => GameEvent::RollResult {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
dice: *dice,
|
||||||
|
},
|
||||||
|
Self::Mark {
|
||||||
|
player_id: _,
|
||||||
|
points,
|
||||||
|
} => GameEvent::Mark {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
points: *points,
|
||||||
|
},
|
||||||
|
Self::Go { player_id: _ } => GameEvent::Go {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
},
|
||||||
|
Self::Move {
|
||||||
|
player_id: _,
|
||||||
|
moves: (move1, move2),
|
||||||
|
} => Self::Move {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
moves: (move1.mirror(), move2.mirror()),
|
||||||
|
},
|
||||||
|
Self::BeginGame { goes_first } => GameEvent::BeginGame {
|
||||||
|
goes_first: (if *goes_first == 1 { 2 } else { 1 }),
|
||||||
|
},
|
||||||
|
Self::EndGame { reason } => GameEvent::EndGame { reason: *reason },
|
||||||
|
Self::PlayError => GameEvent::PlayError,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -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