[position] Streamline the implementation of castling_{king,rook}
Instead of using .and_then with an if/else, use .filter and pass the predicate. Saves a few lines.
This commit is contained in:
parent
feaa81bbd8
commit
85c1a395c4
1 changed files with 6 additions and 14 deletions
|
@ -69,23 +69,15 @@ impl Position {
|
|||
}
|
||||
|
||||
pub(crate) fn castling_king(&self, square: Square) -> Option<Piece> {
|
||||
self.get_piece(square).and_then(|piece| {
|
||||
if piece.color == self.board.active_color && piece.is_king() {
|
||||
Some(piece)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
let active_color = self.board.active_color;
|
||||
self.get_piece(square)
|
||||
.filter(|piece| piece.color == active_color && piece.is_king())
|
||||
}
|
||||
|
||||
pub(crate) fn castling_rook(&self, square: Square) -> Option<Piece> {
|
||||
self.get_piece(square).and_then(|piece| {
|
||||
if piece.color == self.board.active_color && piece.is_rook() {
|
||||
Some(piece)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
let active_color = self.board.active_color;
|
||||
self.get_piece(square)
|
||||
.filter(|piece| piece.color == active_color && piece.is_rook())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue