[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:
Eryn Wells 2024-01-17 08:48:23 -08:00
parent 4fe9be036d
commit f337b8053d

View file

@ -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)]