const Game = struct {
bitboards: [12]BitBoard = blk: {
var bbs: [12]BitBoard = undefined;
for (bbs) |*bb| {
bb.* = BitBoard{};
}
break :blk bbs;
},
attacks: Attacks,
fn reset(self: *@This()) void {
for (self.bitboards) |*bb| {
bb.board = 0;
}
}
fn init(self: *@This()) void {
// white pawns
self.bitboards[PE.P.int()].setSlice(&[_]Square{ .a2, .b2, .c2, .d2, .e2, .f2, .g2, .h2 });
// white knights
self.bitboards[PE.N.int()].setSlice(&[_]Square{ .b1, .g1 });
// white bishops
self.bitboards[PE.B.int()].setSlice(&[_]Square{ .c1, .f1 });
// white rooks
self.bitboards[PE.R.int()].setSlice(&[_]Square{ .a1, .h1 });
// white queen
self.bitboards[PE.Q.int()].set(.d1);
// white king
self.bitboards[PE.K.int()].set(.e1);
// black pawns
self.bitboards[PE.p.int()].setSlice(&[_]Square{ .a7, .b7, .c7, .d7, .e7, .f7, .g7, .h7 });
// black knights
self.bitboards[PE.n.int()].setSlice(&[_]Square{ .b8, .g8 });
// black bishops
self.bitboards[PE.b.int()].setSlice(&[_]Square{ .c8, .f8 });
// black rooks
self.bitboards[PE.r.int()].setSlice(&[_]Square{ .a8, .h8 });
// black queen
self.bitboards[PE.q.int()].set(.d8);
// black king
self.bitboards[PE.k.int()].set(.e8);
}
fn show(self: @This()) void {
std.debug.print("\n", .{});
var rank: usize = 0;
while (rank < SIZE) : (rank += 1) {
var file: usize = 0;
FILE: while (file < SIZE) : (file += 1) {
if (file == 0) std.debug.print("{d}| ", .{SIZE - rank});
const square = @intCast(u6, rank * SIZE + file);
for (self.bitboards) |bb, idx| {
if (bb.board & (@as(BoardType, 1) << square) != 0) {
std.debug.print("{c} ", .{@intToEnum(PE, idx).char()});
continue :FILE;
}
}
std.debug.print(". ", .{});
}
std.debug.print("\n", .{});
}
std.debug.print("{s:>18}\n", .{"---------------"});
std.debug.print("{s:>18}\n", .{"a b c d e f g h"});
}
};
test "Game" {
var game = Game{ .attacks = Attacks.init() };
game.init();
game.show();
}