chore: refactor
This commit is contained in:
parent
30b401fb2b
commit
ba0dffab22
17
src/lib.rs
17
src/lib.rs
@ -505,7 +505,7 @@ impl BoardState {
|
||||
players: Default::default(),
|
||||
mail: Default::default(),
|
||||
ep_square: self.ep_square.map(|sq| sq.mirror_vert()),
|
||||
castle: CastleRights (self.castle.0),
|
||||
castle: CastleRights(self.castle.0),
|
||||
};
|
||||
|
||||
new_board.castle.0.reverse();
|
||||
@ -632,9 +632,18 @@ mod tests {
|
||||
#[test]
|
||||
fn test_flip_colors() {
|
||||
let test_cases = [
|
||||
("2kqrbnp/8/8/8/8/8/8/2KQRBNP w - - 0 1", "2kqrbnp/8/8/8/8/8/8/2KQRBNP b - - 0 1"),
|
||||
("2kqrbnp/8/8/8/8/8/6N1/2KQRB1P w - a1 0 1", "2kqrb1p/6n1/8/8/8/8/8/2KQRBNP b - a8 0 1"),
|
||||
("r3k2r/8/8/8/8/8/8/R3K2R w Kq - 0 1", "r3k2r/8/8/8/8/8/8/R3K2R b Qk - 0 1"),
|
||||
(
|
||||
"2kqrbnp/8/8/8/8/8/8/2KQRBNP w - - 0 1",
|
||||
"2kqrbnp/8/8/8/8/8/8/2KQRBNP b - - 0 1",
|
||||
),
|
||||
(
|
||||
"2kqrbnp/8/8/8/8/8/6N1/2KQRB1P w - a1 0 1",
|
||||
"2kqrb1p/6n1/8/8/8/8/8/2KQRBNP b - a8 0 1",
|
||||
),
|
||||
(
|
||||
"r3k2r/8/8/8/8/8/8/R3K2R w Kq - 0 1",
|
||||
"r3k2r/8/8/8/8/8/8/R3K2R b Qk - 0 1",
|
||||
),
|
||||
];
|
||||
for (tc, expect) in test_cases {
|
||||
let tc = BoardState::from_fen(tc).unwrap();
|
||||
|
@ -663,16 +663,16 @@ mod tests {
|
||||
|
||||
/// Generate new test cases by flipping colors on existing ones.
|
||||
fn flip_test_case(board: BoardState, moves: &Vec<Move>) -> (BoardState, Vec<Move>) {
|
||||
let mut move_vec = moves.iter().map(|mv| Move {
|
||||
let mut move_vec = moves
|
||||
.iter()
|
||||
.map(|mv| Move {
|
||||
src: mv.src.mirror_vert(),
|
||||
dest: mv.dest.mirror_vert(),
|
||||
move_type: mv.move_type,
|
||||
}).collect::<Vec<Move>>();
|
||||
})
|
||||
.collect::<Vec<Move>>();
|
||||
move_vec.sort_unstable();
|
||||
(
|
||||
board.flip_colors(),
|
||||
move_vec,
|
||||
)
|
||||
(board.flip_colors(), move_vec)
|
||||
}
|
||||
|
||||
/// Test movegen through contrived positions.
|
||||
@ -914,7 +914,13 @@ mod tests {
|
||||
let anti_moves = anti_moves;
|
||||
|
||||
assert_eq!(moves, expected_moves, "failed tc {}", board.to_fen());
|
||||
assert_eq!(anti_moves, anti_expected_moves, "failed anti-tc '{}' (originally '{}')", anti_board.to_fen(), board.to_fen());
|
||||
assert_eq!(
|
||||
anti_moves,
|
||||
anti_expected_moves,
|
||||
"failed anti-tc '{}' (originally '{}')",
|
||||
anti_board.to_fen(),
|
||||
board.to_fen()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user