fn setOccupancy(index: usize, attack_mask: BoardType) BoardType {
var occupancy: BitBoard = .{};
var attack: BitBoard = .{ .board = attack_mask };
var count: u6 = 0;
while (count < @popCount(attack_mask)) : (count += 1) {
const square = @ctz(attack.board);
attack.pop(@intToEnum(Square, square));
if (index & @as(BoardType, 1) << count != 0) {
occupancy.set(@intToEnum(Square, square));
}
}
return occupancy.board;
}
test "occupancy bits" {
const attack_mask = Attacks.genSteps(.a1, .rook, .white);
var occupancy: BitBoard = .{};
occupancy.board = setOccupancy(4095, attack_mask);
var expected: BitBoard = .{};
expected.setSlice(&[_]Square{ .a2, .a3, .a4, .a5, .a6, .a7, .b1, .c1, .d1, .e1, .f1, .g1 });
try std.testing.expectEqual(expected, occupancy);
}