diff --git a/board/src/position/position.rs b/board/src/position/position.rs index a307b71..d45fd1d 100644 --- a/board/src/position/position.rs +++ b/board/src/position/position.rs @@ -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)]