YCH5WGGP3PPG2PUNVJIJ6SQXDPYU7NGCVQEJYN27B6FYV5JYQOMQC
GZPVUGLJGD3VGLIK7JDABQ24E5SWN5CYRDGI6PIAFZ2BIMRDMANQC
7T5U3ARTEEAORKCSJY763X5TJRGHCEQK3OW323YO5CZIM77EH77AC
BL3ZR4OWJM54HFXUNMUZKB5YQYVBT7ETFIXCOXWL6S5SZFM6IFDQC
WTTQGET65BQV7NSFOI75JGCTWFS6R73OFZE4V63JYWAODNIOUAHQC
ET37VV7TCQDN6RWF46EUJB6EPNSDOX5TI25NW4P4H5HI4VOTARZQC
TDHJSFFSJZBEZFMDHPLRSVB6CIVJ7AWGGNIC3WUCADQLQSIQKXDAC
SNMQLFZFCV5XTPRLSD7SV4RPVOGUVJOYCZAKI5ATCEPSI5JMGVAAC
board: BoardType = 0,
pub fn set(self: *@This(), square: Square) void {
self.board |= @as(BoardType, 1) << square.int();
}
// zig fmt: off
a8:bool=false, b8:bool=false, c8:bool=false, d8:bool=false, e8:bool=false, f8:bool=false, g8:bool=false, h8:bool=false,
a7:bool=false, b7:bool=false, c7:bool=false, d7:bool=false, e7:bool=false, f7:bool=false, g7:bool=false, h7:bool=false,
a6:bool=false, b6:bool=false, c6:bool=false, d6:bool=false, e6:bool=false, f6:bool=false, g6:bool=false, h6:bool=false,
a5:bool=false, b5:bool=false, c5:bool=false, d5:bool=false, e5:bool=false, f5:bool=false, g5:bool=false, h5:bool=false,
a4:bool=false, b4:bool=false, c4:bool=false, d4:bool=false, e4:bool=false, f4:bool=false, g4:bool=false, h4:bool=false,
a3:bool=false, b3:bool=false, c3:bool=false, d3:bool=false, e3:bool=false, f3:bool=false, g3:bool=false, h3:bool=false,
a2:bool=false, b2:bool=false, c2:bool=false, d2:bool=false, e2:bool=false, f2:bool=false, g2:bool=false, h2:bool=false,
a1:bool=false, b1:bool=false, c1:bool=false, d1:bool=false, e1:bool=false, f1:bool=false, g1:bool=false, h1:bool=false,
// zig fmt: on
bb.set(.a8);
try std.testing.expectEqual(@as(BoardType, 1), bb.board);
bb.unSet(.a8);
bb.set(.h1);
const exp = @as(BoardType, 1) << @as(u6, 63);
try std.testing.expectEqual(exp, bb.board);
}
{ // flip
var bb: BitBoard = .{};
bb.set(.e4);
try std.testing.expect(bb.isSet(.e4));
bb.set(.f1);
try std.testing.expect(bb.isSet(.f1));
bb.flip(.e4);
bb.flip(.f1);
try std.testing.expectEqual(@as(BoardType, 0), bb.board);
bb.flip(.f1); // sets f1 again
try std.testing.expectEqual(
@as(BoardType, @as(BoardType, 1) << @enumToInt(Square.f1)),
bb.board,
);
}
{ // pop
var bb: BitBoard = .{};
bb.set(.e4);
bb.set(.f1);
bb.pop(.e4);
bb.pop(.f1);
bb.set(.g3);
try std.testing.expectEqual(
@as(BoardType, @as(BoardType, 1) << @enumToInt(Square.g3)),
bb.board,
);
bb.pop(.e4); // does nothing
try std.testing.expectEqual(
@as(BoardType, @as(BoardType, 1) << @enumToInt(Square.g3)),
bb.board,
);
}
}