[position] Implement Position::king_bitboard to easily get the king bitboard for a player
Rewrite king_square() and is_king_in_check() in terms of king_bitboard().
This commit is contained in:
parent
357b811518
commit
26aedd8899
1 changed files with 7 additions and 4 deletions
|
@ -235,13 +235,16 @@ impl Position {
|
|||
}
|
||||
|
||||
pub(crate) fn is_king_in_check(&self) -> bool {
|
||||
let sight_of_opposing_player = self.sight_of_player(self.color_to_move.other());
|
||||
sight_of_opposing_player.is_set(self.king_square(self.color_to_move))
|
||||
let danger_squares = self.king_danger(self.color_to_move);
|
||||
(danger_squares & self.king_bitboard(self.color_to_move)).is_empty()
|
||||
}
|
||||
|
||||
fn king_bitboard(&self, player: Color) -> &BitBoard {
|
||||
self.pieces.bitboard_for_piece(&Piece::king(player))
|
||||
}
|
||||
|
||||
pub(crate) fn king_square(&self, player: Color) -> Square {
|
||||
self.pieces
|
||||
.bitboard_for_piece(&Piece::king(player))
|
||||
self.king_bitboard(player)
|
||||
.occupied_squares()
|
||||
.next()
|
||||
.unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue