[board, position] Add a color argument to opposing_sight
New convention: active_color_ methods operate on the active color of the Board. Methods without that prefix take a color parameter and operate on that. Refactor opposing_sight to do this.
This commit is contained in:
parent
a92ec9aba3
commit
0abe9b6c19
3 changed files with 10 additions and 7 deletions
|
@ -61,7 +61,7 @@ impl Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
// King cannot pass through check.
|
// King cannot pass through check.
|
||||||
let opposing_sight = self.opposing_sight();
|
let opposing_sight = self.opposing_sight(active_color);
|
||||||
let opposing_pieces_can_see_castling_path =
|
let opposing_pieces_can_see_castling_path =
|
||||||
(parameters.check & opposing_sight).is_populated();
|
(parameters.check & opposing_sight).is_populated();
|
||||||
if opposing_pieces_can_see_castling_path {
|
if opposing_pieces_can_see_castling_path {
|
||||||
|
|
|
@ -44,14 +44,17 @@ impl Board {
|
||||||
.fold(BitBoard::empty(), BitOr::bitor)
|
.fold(BitBoard::empty(), BitOr::bitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn active_color_opposing_sight(&self) -> BitBoard {
|
||||||
|
self.opposing_sight(self.active_color)
|
||||||
|
}
|
||||||
|
|
||||||
/// A [`BitBoard`] of all squares visible by colors that oppose the given color.
|
/// A [`BitBoard`] of all squares visible by colors that oppose the given color.
|
||||||
pub fn opposing_sight(&self) -> BitBoard {
|
pub fn opposing_sight(&self, color: Color) -> BitBoard {
|
||||||
// TODO: Probably want to implement a caching layer here.
|
// TODO: Probably want to implement a caching layer here.
|
||||||
let active_color = self.active_color;
|
|
||||||
Color::ALL
|
Color::ALL
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|c| {
|
.filter_map(|c| {
|
||||||
if c == active_color {
|
if c == color {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.friendly_sight(c))
|
Some(self.friendly_sight(c))
|
||||||
|
@ -223,7 +226,7 @@ mod tests {
|
||||||
Black Rook on E7,
|
Black Rook on E7,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sight = pos.opposing_sight();
|
let sight = pos.active_color_opposing_sight();
|
||||||
assert_eq!(sight, bitboard![A7 B7 C7 D7 F7 G7 H7 E8 E6 E5 E4]);
|
assert_eq!(sight, bitboard![A7 B7 C7 D7 F7 G7 H7 E8 E6 E5 E4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ impl Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`BitBoard`] of all squares visible by colors that oppose the given color.
|
/// A [`BitBoard`] of all squares visible by colors that oppose the given color.
|
||||||
pub fn opposing_sight(&self) -> BitBoard {
|
pub fn active_color_opposing_sight(&self) -> BitBoard {
|
||||||
self.board.opposing_sight()
|
self.board.active_color_opposing_sight()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue