[board] Break getting the square the king is on into a separate helper method
Implement Position::king_square() and use it in is_king_in_check()
This commit is contained in:
parent
4fe9be036d
commit
f337b8053d
1 changed files with 7 additions and 4 deletions
|
@ -212,12 +212,15 @@ 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());
|
||||
let king_square = self
|
||||
.bitboard_for_piece(Piece::king(self.color_to_move))
|
||||
sight_of_opposing_player.is_set(self.king_square())
|
||||
}
|
||||
|
||||
fn king_square(&self) -> Square {
|
||||
self.bitboard_for_piece(Piece::king(self.color_to_move))
|
||||
.occupied_squares()
|
||||
.next()
|
||||
.unwrap();
|
||||
sight_of_opposing_player.is_set(king_square)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue