wip fix exit
This commit is contained in:
parent
24a6a90fe5
commit
e2367be24f
2 changed files with 90 additions and 20 deletions
|
|
@ -454,7 +454,7 @@ impl Board {
|
|||
}
|
||||
};
|
||||
|
||||
let mut farthest_exit_move = 25;
|
||||
// let mut farthest_exit_move = 25;
|
||||
for (field, count) in self.get_color_fields(color) {
|
||||
// check rest corner exit
|
||||
if field == self.get_color_corner(&color) && count == 2 && check_rest_corner_exit {
|
||||
|
|
@ -468,7 +468,7 @@ impl Board {
|
|||
// if with_excedants && !forbid_exits && field < farthest_exit_move && 2 < count {
|
||||
if with_excedants && !forbid_exits {
|
||||
dest = 0;
|
||||
farthest_exit_move = field;
|
||||
// farthest_exit_move = field;
|
||||
// println!("farthest is now {farthest_exit_move}");
|
||||
} else {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -346,14 +346,17 @@ impl MoveRules {
|
|||
|
||||
// The chosen checker must be the farthest from exit
|
||||
// For chained moves (tout d'une), we need to check the board state AFTER the first move
|
||||
let board_to_check = if moves.0.get_to() == moves.1.get_from() {
|
||||
// Chained move: apply first move to get the board state
|
||||
let mut board_copy = self.board.clone();
|
||||
let _ = board_copy.move_checker(&Color::White, moves.0);
|
||||
board_copy
|
||||
} else {
|
||||
self.board.clone()
|
||||
};
|
||||
// let board_to_check = if moves.0.get_to() == moves.1.get_from() {
|
||||
// // Chained move: apply first move to get the board state
|
||||
// let mut board_copy = self.board.clone();
|
||||
// let _ = board_copy.move_checker(&Color::White, moves.0);
|
||||
// board_copy
|
||||
// } else {
|
||||
// self.board.clone()
|
||||
// };
|
||||
let board_to_check = self.board.clone();
|
||||
let board_to_check2 = self.board.clone();
|
||||
let _ = board_to_check2.move_checker(&Color::White, moves.0);
|
||||
|
||||
let mut checkers = board_to_check.get_color_fields(Color::White);
|
||||
checkers.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
|
|
@ -897,6 +900,19 @@ mod tests {
|
|||
);
|
||||
assert!(state.moves_follows_dices(&moves));
|
||||
assert!(state.moves_allowed(&moves).is_ok());
|
||||
|
||||
state.board.set_positions(
|
||||
&Color::White,
|
||||
[
|
||||
-5, -2, -2, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 2, 3, 2, 3,
|
||||
],
|
||||
);
|
||||
state.dice.values = (4, 5);
|
||||
let moves = (
|
||||
CheckerMove::new(19, 24).unwrap(),
|
||||
CheckerMove::new(22, 0).unwrap(),
|
||||
);
|
||||
assert!(state.moves_allowed(&moves).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1457,6 +1473,23 @@ mod tests {
|
|||
vec![moves],
|
||||
state.get_possible_moves_sequences(true, vec![])
|
||||
);
|
||||
|
||||
let mut board = Board::new();
|
||||
board.set_positions(
|
||||
&crate::Color::White,
|
||||
[
|
||||
-7, -4, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0, 3, 2, 1, 2, 3, 4,
|
||||
],
|
||||
);
|
||||
let state = MoveRules::new(&Color::White, &board, Dice { values: (2, 6) });
|
||||
let moves = (
|
||||
CheckerMove::new(19, 21).unwrap(),
|
||||
CheckerMove::new(23, 0).unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
vec![moves],
|
||||
state.get_possible_moves_sequences(true, vec![])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1492,16 +1525,10 @@ mod tests {
|
|||
-5, -2, -2, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 2, 3, 2, 3,
|
||||
],
|
||||
);
|
||||
let moves = vec![
|
||||
(
|
||||
CheckerMove::new(19, 23).unwrap(),
|
||||
CheckerMove::new(22, 0).unwrap(),
|
||||
),
|
||||
(
|
||||
CheckerMove::new(19, 24).unwrap(),
|
||||
CheckerMove::new(22, 0).unwrap(),
|
||||
),
|
||||
];
|
||||
let moves = vec![(
|
||||
CheckerMove::new(19, 23).unwrap(),
|
||||
CheckerMove::new(22, 0).unwrap(),
|
||||
)];
|
||||
assert_eq!(
|
||||
moves,
|
||||
state.get_possible_moves_sequences_by_dices(
|
||||
|
|
@ -1512,6 +1539,43 @@ mod tests {
|
|||
vec![]
|
||||
)
|
||||
);
|
||||
let moves = vec![(
|
||||
CheckerMove::new(19, 24).unwrap(),
|
||||
CheckerMove::new(22, 0).unwrap(),
|
||||
)];
|
||||
assert_eq!(
|
||||
moves,
|
||||
state.get_possible_moves_sequences_by_dices(
|
||||
state.dice.values.1,
|
||||
state.dice.values.0,
|
||||
true,
|
||||
false,
|
||||
vec![]
|
||||
)
|
||||
);
|
||||
|
||||
let mut board = Board::new();
|
||||
board.set_positions(
|
||||
&crate::Color::White,
|
||||
[
|
||||
-7, -4, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0, 3, 2, 1, 2, 3, 4,
|
||||
],
|
||||
);
|
||||
let state = MoveRules::new(&Color::White, &board, Dice { values: (2, 6) });
|
||||
let moves = (
|
||||
CheckerMove::new(19, 21).unwrap(),
|
||||
CheckerMove::new(23, 0).unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
vec![moves],
|
||||
state.get_possible_moves_sequences_by_dices(
|
||||
state.dice.values.0,
|
||||
state.dice.values.1,
|
||||
true,
|
||||
false,
|
||||
vec![]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1529,6 +1593,12 @@ mod tests {
|
|||
CheckerMove::new(22, 0).unwrap(),
|
||||
);
|
||||
assert!(state.check_exit_rules(&moves).is_ok());
|
||||
|
||||
let moves = (
|
||||
CheckerMove::new(19, 24).unwrap(),
|
||||
CheckerMove::new(22, 0).unwrap(),
|
||||
);
|
||||
assert!(state.check_exit_rules(&moves).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue