ET37VV7TCQDN6RWF46EUJB6EPNSDOX5TI25NW4P4H5HI4VOTARZQC
fn genRookAttacks() [@typeInfo(Chess.Square).Enum.fields.len]Chess.BoardType {
var ret: [64]Chess.BoardType = [_]Chess.BoardType{0} ** 64;
for (std.enums.values(Chess.Square)) |square| {
ret[@enumToInt(square)] = genSteps(square, .rook, .white);
}
return ret;
}
test "RookAttacks" {
var bb: Chess.BitBoard = .{};
const ra = genRookAttacks();
{
bb.board = 0;
bb.setSlice(&[_]Chess.Square{ .b1, .c1, .d1, .e1, .f1, .g2, .g3, .g4, .g5, .g6, .g7 });
try std.testing.expectEqual(
bb.board,
ra[@enumToInt(Chess.Square.g1)],
);
}
{
bb.board = 0;
bb.setSlice(&[_]Chess.Square{ .b1, .c1, .d1, .e1, .f1, .g1, .h2, .h3, .h4, .h5, .h6, .h7 });
try std.testing.expectEqual(
bb.board,
ra[@enumToInt(Chess.Square.h1)],
);
}
}
.king => [_][2]i3{
.{ -1, -1 },
.{ -1, 1 },
.{ 1, -1 },
.{ 1, 1 },
.{ -1, 0 },
.{ 0, 1 },
.{ 1, 0 },
.{ 0, -1 },
},
.king => [_][2]i3{ .{ -1, -1 }, .{ -1, 1 }, .{ 1, -1 }, .{ 1, 1 }, .{ -1, 0 }, .{ 0, 1 }, .{ 1, 0 }, .{ 0, -1 } },
.rook => [_][2]i3{ .{ -1, 0 }, .{ 1, 0 }, .{ 0, -1 }, .{ 0, 1 }, .{ -1, 0 }, .{ 1, 0 }, .{ 0, -1 }, .{ 0, 1 } },