[board] Trying out a new naming convention in the check methods
I've been bothered by certain instances where the color has already been unwrapped from an Option<Color> 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<Color> 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.
This commit is contained in:
parent
f8a3d5831e
commit
f47654cc98
1 changed files with 9 additions and 4 deletions
|
@ -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<Color>) -> 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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue