From ba0dffab2229d8fe78f290ec4ac2cfc45a484ec0 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Mon, 21 Oct 2024 14:43:18 -0400 Subject: [PATCH] chore: refactor --- src/lib.rs | 17 +++++++++++++---- src/movegen.rs | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 548e80f..d933d2f 100644 --- a/src/lib.rs +++ b/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(); diff --git a/src/movegen.rs b/src/movegen.rs index 3f77899..2a0624d 100644 --- a/src/movegen.rs +++ b/src/movegen.rs @@ -663,16 +663,16 @@ mod tests { /// Generate new test cases by flipping colors on existing ones. fn flip_test_case(board: BoardState, moves: &Vec) -> (BoardState, Vec) { - 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::>(); + }) + .collect::>(); 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() + ); } }