[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> {
|
pub(crate) fn castling_king(&self, square: Square) -> Option<Piece> {
|
||||||
self.get_piece(square).and_then(|piece| {
|
let active_color = self.board.active_color;
|
||||||
if piece.color == self.board.active_color && piece.is_king() {
|
self.get_piece(square)
|
||||||
Some(piece)
|
.filter(|piece| piece.color == active_color && piece.is_king())
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn castling_rook(&self, square: Square) -> Option<Piece> {
|
pub(crate) fn castling_rook(&self, square: Square) -> Option<Piece> {
|
||||||
self.get_piece(square).and_then(|piece| {
|
let active_color = self.board.active_color;
|
||||||
if piece.color == self.board.active_color && piece.is_rook() {
|
self.get_piece(square)
|
||||||
Some(piece)
|
.filter(|piece| piece.color == active_color && piece.is_rook())
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue