diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-22 18:14:16 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-22 18:14:16 +0300 |
commit | f5fd1903c995894bbb8574f1191f4f04ae2f2d57 (patch) | |
tree | 8ea27d13d961f636ced578a88fe2c203cd905473 /src | |
parent | cd1e76b490c34ae2e2eaeed27eebe524d3cad486 (diff) | |
download | chessnost-f5fd1903c995894bbb8574f1191f4f04ae2f2d57.tar.gz |
feat: compute occupancy by color
Diffstat (limited to 'src')
-rw-r--r-- | src/board.rs | 13 |
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); } } |