[board, position] Simplify check methods
Only one check-testing method, Board::is_in_check(), that tests if the current active player is in check. It doesn't make sense to test if the non-active player is in check.
This commit is contained in:
parent
a30553503f
commit
e3d17219ad
3 changed files with 9 additions and 17 deletions
|
@ -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<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 {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue