);
}
}
fn genKingAttacks() [@typeInfo(Square).Enum.fields.len]BoardType {
var ret: [64]BoardType = [_]BoardType{0} ** 64;
var bb: BitBoard = .{};
for (std.enums.values(Square)) |square| {
bb.board = 0;
bb.set(square);
ret[@enumToInt(square)] |= bb.board >> 8;
if (bb.board & Square.fileBits('h') == 0)
ret[@enumToInt(square)] |= bb.board >> 7;
if (bb.board & Square.fileBits('a') == 0)
ret[@enumToInt(square)] |= (bb.board >> 9 | bb.board >> 1);
ret[@enumToInt(square)] |= bb.board << 8;
if (bb.board & Square.fileBits('a') == 0)
ret[@enumToInt(square)] |= bb.board << 7;
if (bb.board & Square.fileBits('h') == 0)
ret[@enumToInt(square)] |= (bb.board << 9 | bb.board << 1);
}
return ret;
}
test "KingAttacks" {
const ka = genKingAttacks();
{ // full move
var bb: BitBoard = .{};
bb.set(.c5);
bb.set(.d5);
bb.set(.e5);
bb.set(.c3);
bb.set(.d3);
bb.set(.e3);
bb.set(.c4);
bb.set(.e4);
try std.testing.expectEqual(
bb.board,
ka[@enumToInt(Square.d4)],
);
}
{ // sides - 5 moves
var bb: BitBoard = .{};
bb.set(.a5);
bb.set(.a3);
bb.set(.b5);
bb.set(.b4);
bb.set(.b3);
try std.testing.expectEqual(
bb.board,
ka[@enumToInt(Square.a4)],