diff --git a/board/src/check.rs b/board/src/check.rs index ba9f06d..6d8ceba 100644 --- a/board/src/check.rs +++ b/board/src/check.rs @@ -5,18 +5,10 @@ use chessfriend_bitboard::BitBoard; use chessfriend_core::{Color, Piece}; impl Board { + /// Return whether the active color is in check. #[must_use] - pub fn active_color_is_in_check(&self) -> bool { - self.unwrapped_color_is_in_check(self.active_color()) - } - - #[must_use] - pub fn color_is_in_check(&self, color: Option) -> bool { - self.unwrapped_color_is_in_check(self.unwrap_color(color)) - } - - #[must_use] - pub fn unwrapped_color_is_in_check(&self, color: Color) -> bool { + pub fn is_in_check(&self) -> bool { + let color = self.active_color(); let king = self.king_bitboard(color); let opposing_sight = self.opposing_sight(color); (king & opposing_sight).is_populated() @@ -39,7 +31,7 @@ mod tests { Black Rook on F3, ); - assert!(board.unwrapped_color_is_in_check(Color::White)); + assert!(board.is_in_check()); } #[test] @@ -49,6 +41,6 @@ mod tests { Black Rook on B4, ); - assert!(!board.unwrapped_color_is_in_check(Color::White)); + assert!(!board.is_in_check()); } } diff --git a/position/src/position.rs b/position/src/position.rs index d2a82f3..1763875 100644 --- a/position/src/position.rs +++ b/position/src/position.rs @@ -129,7 +129,7 @@ impl Position { ); }); - let move_is_legal = !test_board.color_is_in_check(Some(active_color_before_move)); + let move_is_legal = !test_board.is_in_check(); test_board.unmake_move(&record).unwrap_or_else(|err| { panic!( diff --git a/position/tests/peterellisjones.rs b/position/tests/peterellisjones.rs index ea90a2f..06ccc45 100644 --- a/position/tests/peterellisjones.rs +++ b/position/tests/peterellisjones.rs @@ -107,7 +107,7 @@ fn en_passant_check_capture() { White Pawn on D4, ], D3); - assert!(pos.board().active_color_is_in_check()); + assert!(pos.board().is_in_check()); let generated_moves: HashSet<_> = pos.all_legal_moves(Some(Color::Black)).collect(); @@ -123,7 +123,7 @@ fn en_passant_check_block() { White Queen on F1, ], D3); - assert!(pos.board().active_color_is_in_check()); + assert!(pos.board().is_in_check()); let generated_moves: HashSet<_> = pos.all_legal_moves(Some(Color::Black)).collect(); @@ -139,7 +139,7 @@ fn pinned_pieces_rook_cannot_move_out_of_pin() { White King on C1, ]); - assert!(!pos.board().active_color_is_in_check()); + assert!(!pos.board().is_in_check()); let rook_moves: HashSet<_> = pos.all_legal_moves(None).collect();