chore: refactor

This commit is contained in:
dogeystamp 2024-10-21 14:43:18 -04:00
parent 30b401fb2b
commit ba0dffab22
2 changed files with 26 additions and 11 deletions

View File

@ -505,7 +505,7 @@ impl BoardState {
players: Default::default(), players: Default::default(),
mail: Default::default(), mail: Default::default(),
ep_square: self.ep_square.map(|sq| sq.mirror_vert()), 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(); new_board.castle.0.reverse();
@ -632,9 +632,18 @@ mod tests {
#[test] #[test]
fn test_flip_colors() { fn test_flip_colors() {
let test_cases = [ 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"), "2kqrbnp/8/8/8/8/8/8/2KQRBNP w - - 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 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 { for (tc, expect) in test_cases {
let tc = BoardState::from_fen(tc).unwrap(); let tc = BoardState::from_fen(tc).unwrap();

View File

@ -663,16 +663,16 @@ mod tests {
/// Generate new test cases by flipping colors on existing ones. /// Generate new test cases by flipping colors on existing ones.
fn flip_test_case(board: BoardState, moves: &Vec<Move>) -> (BoardState, Vec<Move>) { 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(), src: mv.src.mirror_vert(),
dest: mv.dest.mirror_vert(), dest: mv.dest.mirror_vert(),
move_type: mv.move_type, move_type: mv.move_type,
}).collect::<Vec<Move>>(); })
.collect::<Vec<Move>>();
move_vec.sort_unstable(); move_vec.sort_unstable();
( (board.flip_colors(), move_vec)
board.flip_colors(),
move_vec,
)
} }
/// Test movegen through contrived positions. /// Test movegen through contrived positions.
@ -914,7 +914,13 @@ mod tests {
let anti_moves = anti_moves; let anti_moves = anti_moves;
assert_eq!(moves, expected_moves, "failed tc {}", board.to_fen()); 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()
);
} }
} }