aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-22 18:31:44 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-22 18:31:44 +0300
commit393a3e57d0323e4403ad73192cecc1bc6e471435 (patch)
tree3f06aca28a0719809d14cecc5a21e80a28f84aa7 /src
parentf5fd1903c995894bbb8574f1191f4f04ae2f2d57 (diff)
downloadchessnost-393a3e57d0323e4403ad73192cecc1bc6e471435.tar.gz
refactor: compute pieces by color separately
Diffstat (limited to 'src')
-rw-r--r--src/board.rs14
1 files changed, 11 insertions, 3 deletions
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
}