From f47654cc98af10222f9e04b93a27c478e92a2447 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 1 Jun 2025 19:07:58 -0700 Subject: [PATCH] [board] Trying out a new naming convention in the check methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I've been bothered by certain instances where the color has already been unwrapped from an Option but a subsequent call takes an Option, so you have to rewrap it to call the method. I might be overthinking this… For the Board::*_color_is_in_check set of methods, try out this naming convention: active_color_is_in_check() : Operates directly on the Board's active color, no unwrapping required color_is_in_check() : Takes an Option and unwraps it with the active color if None is given unwrapped_color_is_in_check() : Takes a Color and operates on it. This method is called by the two above, but is also public. --- board/src/check.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/board/src/check.rs b/board/src/check.rs index 92fa168..8e6246d 100644 --- a/board/src/check.rs +++ b/board/src/check.rs @@ -7,11 +7,16 @@ use chessfriend_core::{Color, Piece}; impl Board { #[must_use] pub fn active_color_is_in_check(&self) -> bool { - self.color_is_in_check(self.active_color) + self.unwrapped_color_is_in_check(self.active_color) } #[must_use] - pub fn color_is_in_check(&self, color: Color) -> bool { + 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 { let king = self.king_bitboard(color); let opposing_sight = self.opposing_sight(color); (king & opposing_sight).is_populated() @@ -34,7 +39,7 @@ mod tests { Black Rook on F3, ); - assert!(board.color_is_in_check(Color::White)); + assert!(board.unwrapped_color_is_in_check(Color::White)); } #[test] @@ -44,6 +49,6 @@ mod tests { Black Rook on B4, ); - assert!(!board.color_is_in_check(Color::White)); + assert!(!board.unwrapped_color_is_in_check(Color::White)); } }