}
fn genRelevantOccupancy(piece: Pieces) [@typeInfo(Square).Enum.fields.len]BoardType {
var ret: [64]BoardType = [_]BoardType{0} ** 64;
for (std.enums.values(Square)) |square| {
ret[@enumToInt(square)] = @popCount(Attacks.genSteps(square, piece, .white));
}
return ret;
}
test "genRelevantOccupancy" {
{ // bishop
const bishop = genRelevantOccupancy(.bishop);
// zig fmt: off
const expected = [64]BoardType{
6, 5, 5, 5, 5, 5, 5, 6,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 7, 7, 7, 7, 5, 5,
5, 5, 7, 9, 9, 7, 5, 5,
5, 5, 7, 9, 9, 7, 5, 5,
5, 5, 7, 7, 7, 7, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
6, 5, 5, 5, 5, 5, 5, 6,
};
// zig fmt: on
try std.testing.expectEqualSlices(BoardType, &expected, &bishop);
}
{ // rook
const rook = genRelevantOccupancy(.rook);
// zig fmt: off
const expected = [64]BoardType{
12, 11, 11, 11, 11, 11, 11, 12,
11, 10, 10, 10, 10, 10, 10, 11,
11, 10, 10, 10, 10, 10, 10, 11,
11, 10, 10, 10, 10, 10, 10, 11,
11, 10, 10, 10, 10, 10, 10, 11,
11, 10, 10, 10, 10, 10, 10, 11,
11, 10, 10, 10, 10, 10, 10, 11,
12, 11, 11, 11, 11, 11, 11, 12,
};
// zig fmt: on
try std.testing.expectEqualSlices(BoardType, &expected, &rook);
}