RFXUGGUPAFJ7V6BTQZM4SQEAOFLDVWYI5ZIIK6K5EKFDXPPD2ZYQC
XCEYZZXOYMROQEI3QCO4N7JM2XPEOLSHE4ZNRWXGN3VFIO2XCBDQC
A46B5KNQFPTZEIL2JZKD2CQELGU3COE6FGTV2ABS5U7DVTVDGEBQC
} fn fileBits(file: u8) BoardType { const offset = file - 'a'; std.debug.assert(offset < SIZE); var ret: BoardType = 0; var idx: u6 = 0; while (idx < SIZE) : (idx += 1) { ret += @as(BoardType, 1) << idx * SIZE + @intCast(u3, offset); } return ret;
}
fn fileBits(file: u8) BoardType {
const offset = file - 'a';
std.debug.assert(offset < SIZE);
var ret: BoardType = 0;
var idx: u6 = 0;
while (idx < SIZE) : (idx += 1) {
ret += @as(BoardType, 1) << idx * SIZE + @intCast(u3, offset);
return ret;
fn rankBits(rank: u6) BoardType { var ret: BoardType = 0; std.debug.assert(rank > 0 and rank <= SIZE); var idx: u6 = 0; while (idx < SIZE) : (idx += 1) { ret += @as(BoardType, 1) << idx + (SIZE - rank) * SIZE; } return ret; }
fn rankBits(rank: u6) BoardType {
std.debug.assert(rank > 0 and rank <= SIZE);
ret += @as(BoardType, 1) << idx + (SIZE - rank) * SIZE;
fn genPawnAttack() [@typeInfo(Colors).Enum.fields.len][@typeInfo(Square).Enum.fields.len]BoardType {
fn genPawnAttacks() [@typeInfo(Colors).Enum.fields.len][@typeInfo(Square).Enum.fields.len]BoardType {
const a_file = blk: { var bb: BitBoard = .{}; var a_set = [_]Square{ .a8, .a7, .a6, .a5, .a4, .a3, .a2, .a1 }; bb.setSlice(&a_set); break :blk bb.board; };
const a_file = blk: {
var bb: BitBoard = .{};
var a_set = [_]Square{ .a8, .a7, .a6, .a5, .a4, .a3, .a2, .a1 };
bb.setSlice(&a_set);
break :blk bb.board;
};
const h_file = blk: { var bb: BitBoard = .{}; var h_set = [_]Square{ .h8, .h7, .h6, .h5, .h4, .h3, .h2, .h1 }; bb.setSlice(&h_set); break :blk bb.board; };
const h_file = blk: {
var h_set = [_]Square{ .h8, .h7, .h6, .h5, .h4, .h3, .h2, .h1 };
bb.setSlice(&h_set);
if (bb.board & a_file == 0) ret[@enumToInt(color)][@enumToInt(square)] += bb.board >> 9;
if (bb.board & a_file == 0)
ret[@enumToInt(color)][@enumToInt(square)] += bb.board >> 9;
if (bb.board & Square.fileBits('a') == 0) ret[@enumToInt(color)][@enumToInt(square)] |= bb.board >> 9;
if (bb.board & Square.fileBits('a') == 0)
ret[@enumToInt(color)][@enumToInt(square)] |= bb.board >> 9;
if (bb.board & h_file == 0) ret[@enumToInt(color)][@enumToInt(square)] += bb.board >> 7;
if (bb.board & h_file == 0)
ret[@enumToInt(color)][@enumToInt(square)] += bb.board >> 7;
if (bb.board & Square.fileBits('h') == 0) ret[@enumToInt(color)][@enumToInt(square)] |= bb.board >> 7;
if (bb.board & Square.fileBits('h') == 0)
ret[@enumToInt(color)][@enumToInt(square)] |= bb.board >> 7;
if (bb.board & h_file == 0) ret[@enumToInt(color)][@enumToInt(square)] += bb.board << 9;
ret[@enumToInt(color)][@enumToInt(square)] += bb.board << 9;
if (bb.board & Square.fileBits('h') == 0) ret[@enumToInt(color)][@enumToInt(square)] |= bb.board << 9;
ret[@enumToInt(color)][@enumToInt(square)] |= bb.board << 9;
if (bb.board & a_file == 0) ret[@enumToInt(color)][@enumToInt(square)] += bb.board << 7;
ret[@enumToInt(color)][@enumToInt(square)] += bb.board << 7;
if (bb.board & Square.fileBits('a') == 0) ret[@enumToInt(color)][@enumToInt(square)] |= bb.board << 7;
ret[@enumToInt(color)][@enumToInt(square)] |= bb.board << 7;
test "PawnAttack" { const pa = genPawnAttack();
test "PawnAttack" {
const pa = genPawnAttack();
test "PawnAttacks" { const pa = genPawnAttacks();
test "PawnAttacks" {
const pa = genPawnAttacks();