11 constexpr Bitboard(uint64_t value = zero()) : m_value(value) {};
13 constexpr void set(uint64_t value) { m_value = value; }
14 [[nodiscard]]
constexpr uint64_t value()
const {
return m_value; }
16 constexpr Bitboard& operator|=(
const Bitboard& other) {
17 m_value |= other.m_value;
20 constexpr Bitboard& operator&=(
const Bitboard& other) {
21 m_value &= other.m_value;
24 constexpr Bitboard& operator^=(
const Bitboard& other) {
25 m_value ^= other.m_value;
29 constexpr operator uint64_t()
const {
return m_value; }
31 constexpr bool operator==(
const Bitboard& other)
const {
return m_value == other.m_value; }
32 constexpr bool operator!=(
const Bitboard& other)
const {
return m_value != other.m_value; }
34 static constexpr Bitboard zero() {
return 0ULL; }
36 static constexpr Bitboard squareBB(
Square square) {
return (1ULL << square); }
37 static constexpr Bitboard destinationBB(
Square square,
Direction direction) {
38 Square destination = square + direction;
39 return (destination.ok() && Square::distance(square, destination) <= 2) ? squareBB(destination) : zero();
43 [[nodiscard]]
constexpr Bitboard pushed()
const {
53 return (m_value & ~fileBB(File::FH)) << D;
56 return (m_value & ~fileBB(File::FA)) >> -D;
62 static constexpr Bitboard rankBB(
Rank rank) {
63 static constexpr auto table = []()
constexpr {
64 std::array<Bitboard, Rank::number()> t{};
66 constexpr Bitboard RANK_A = 0xFFULL;
68 for (
auto rank : Rank::all()) {
69 t[rank] = (RANK_A << (rank * File::number()));
77 static constexpr Bitboard fileBB(
File file) {
78 static constexpr auto table = []()
constexpr {
79 std::array<Bitboard, File::NB> t{};
81 constexpr Bitboard FILE_A = 0x0101010101010101ULL;
83 for (
auto file : File::all()) {
84 t[file] = (FILE_A << file);
92 static constexpr Bitboard diagBB(
Square square) {
93 static constexpr auto table = []()
constexpr {
94 std::array<Bitboard, Square::NB> t{};
95 for (
auto square : Square::all()) {
96 Bitboard diag = zero();
97 File squareFile = square.file();
98 Rank squareRank = square.rank();
100 for (
auto rank : Rank::all()) {
101 for (
auto file : File::all()) {
103 if (file - rank == squareFile - squareRank) {
104 diag = diag | squareBB(possibleSquare);
112 return table[square];
115 static constexpr Bitboard antiDiagBB(
Square square) {
116 static constexpr auto table = []()
constexpr {
117 std::array<Bitboard, Square::NB> t{};
118 for (
auto square : Square::all()) {
119 Bitboard antiDiag = zero();
120 File squareFile = square.file();
121 Rank squareRank = square.rank();
123 for (
auto rank : Rank::all()) {
124 for (
auto file : File::all()) {
126 if (file + rank == squareFile + squareRank) {
127 antiDiag = antiDiag | squareBB(possibleSquare);
131 t[square] = antiDiag;
135 return table[square];