From f5fd1903c995894bbb8574f1191f4f04ae2f2d57 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 22 Jan 2023 18:14:16 +0300 Subject: feat: compute occupancy by color --- src/board.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/board.rs') 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); } } -- cgit v1.2.3