From 393a3e57d0323e4403ad73192cecc1bc6e471435 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 22 Jan 2023 18:31:44 +0300 Subject: refactor: compute pieces by color separately --- src/board.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/board.rs b/src/board.rs index 55086bf..a078fff 100644 --- a/src/board.rs +++ b/src/board.rs @@ -100,13 +100,21 @@ impl Board { !self.occupancy } - fn color_occupancy(&self, color: Color) -> Bitboard { - let mut occupancy = 0; + fn pieces_by_color(&self, color: Color) -> [Bitboard; 6] { + let mut pieces = [0; 6]; for (piece_type, piece) in self.pieces.iter().enumerate() { if piece_type % 2 == color as usize { - occupancy |= piece; + pieces[piece_type / 2] = *piece; } } + pieces + } + + fn color_occupancy(&self, color: Color) -> Bitboard { + let mut occupancy = 0; + for piece in self.pieces_by_color(color) { + occupancy |= piece; + } occupancy } -- cgit v1.2.3