@@ 282,3 282,23 @@ fn numBishopRelativeOccupancies() [64]u64 {
return occupancies;
}
}
+
+// Given a blockMask, a mask of rays containing potentially blocking pieces for
+// a sliding piece, return a bitboard where 1s are a subset of the 1s in the
+// mask. There are many such subsets, they are indexed by 'i'.
+fn subOccupancy(blockMask: u64, i: u64) u64 {
+ var blockBitCount = @popCount(u64, blockMask);
+ var occupancy: u64 = 0;
+ var mask = blockMask;
+ var count: u6 = 0;
+
+ while (count < blockBitCount) : (count += 1) {
+ var lsbIndex = @intCast(u6, @ctz(u64, mask));
+ mask = resetBit(mask, @intToEnum(Square, lsbIndex));
+
+ if (i & (@as(u64, 1) << count) != 0) {
+ occupancy |= @as(u64, 1) << lsbIndex;
+ }
+ }
+ return occupancy;
+}