aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-22 18:14:16 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-22 18:14:16 +0300
commitf5fd1903c995894bbb8574f1191f4f04ae2f2d57 (patch)
tree8ea27d13d961f636ced578a88fe2c203cd905473
parentcd1e76b490c34ae2e2eaeed27eebe524d3cad486 (diff)
downloadchessnost-f5fd1903c995894bbb8574f1191f4f04ae2f2d57.tar.gz
feat: compute occupancy by color
-rw-r--r--src/board.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/board.rs b/src/board.rs
index b76356f..55086bf 100644
--- a/src/board.rs
+++ b/src/board.rs
@@ -100,6 +100,16 @@ impl Board {
!self.occupancy
}
+ fn color_occupancy(&self, color: Color) -> Bitboard {
+ let mut occupancy = 0;
+ for (piece_type, piece) in self.pieces.iter().enumerate() {
+ if piece_type % 2 == color as usize {
+ occupancy |= piece;
+ }
+ }
+ occupancy
+ }
+
pub fn print(&self) {
println!();
for rank in (0..8).rev() {
@@ -125,6 +135,7 @@ impl Board {
}
+#[derive(Clone, Copy)]
pub enum Color {
White,
Black,
@@ -183,5 +194,7 @@ mod tests {
assert_eq!(pop_count(board.occupancy), 32);
assert_eq!(pop_count(board.empty()), 32);
+ assert_eq!(pop_count(board.color_occupancy(Color::White)), 16);
+ assert_eq!(pop_count(board.color_occupancy(Color::Black)), 16);
}
}