Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/bitboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
return file_mask(2) | file_mask(3) | file_mask(4) | file_mask(5);
}

[[nodiscard]] static Bitboard fill_verticals(const Bitboard mask) {

Check warning on line 54 in src/bitboard.hpp

View workflow job for this annotation

GitHub Actions / Linter / cpp-linter

src/bitboard.hpp:54:65 [readability-identifier-naming]

invalid case style for constant 'mask'
Bitboard result = mask | (mask >> 8);
result |= result >> 16;
result |= result >> 32;
Expand All @@ -78,6 +78,10 @@
return Square{static_cast<u8>(std::countr_zero(m_raw))};
}

[[nodiscard]] bool any() const {
return static_cast<bool>(m_raw);
}

// Rank closest to player
[[nodiscard]] u8 front_rank(Color color) const {
i32 color_shift = color == Color::White ? 0 : 56;
Expand Down Expand Up @@ -107,6 +111,15 @@
}
}

[[nodiscard]] Square frontmost_square(Color color) const {
return color == Color::White ? msb() : lsb();
}

[[nodiscard]] static Bitboard forward_ranks(Color c, Square sq) {
return c == Color::White ? ~rank_mask(0) << (8 * sq.relative_rank(c))
: ~rank_mask(7) >> (8 * sq.relative_rank(c));
}

[[nodiscard]] Bitboard shift_relative(Color perspective, Direction dir) const {
if (perspective == Color::Black) {
dir = static_cast<Direction>((static_cast<u32>(dir) + 4) % 8);
Expand All @@ -114,7 +127,7 @@
return shift(dir);
}

[[nodiscard]] Bitboard shift_relative(Color perspective, Direction dir, const i32 times) const {

Check warning on line 130 in src/bitboard.hpp

View workflow job for this annotation

GitHub Actions / Linter / cpp-linter

src/bitboard.hpp:130:87 [readability-identifier-naming]

invalid case style for constant 'times'
if (perspective == Color::Black) {
dir = static_cast<Direction>((static_cast<u32>(dir) + 4) % 8);
}
Expand Down Expand Up @@ -215,6 +228,24 @@
friend constexpr Bitboard& operator^=(Bitboard& a, Bitboard b) {
return a = a ^ b;
}
friend constexpr Bitboard& operator>>=(Bitboard& a, i32 shift) {
return a = a >> shift;
}
friend constexpr Bitboard& operator<<=(Bitboard& a, i32 shift) {
return a = a << shift;
}

// ostream support for debugging
friend std::ostream& operator<<(std::ostream& os, const Bitboard& bb) {
for (i32 rank = 7; rank >= 0; rank--) {
for (i32 file = 0; file < 8; file++) {
Square sq = Square::from_file_and_rank(file, rank);
os << (bb.is_set(sq) ? '1' : '.') << ' ';
}
os << std::endl;
}
return os;
}

private:
u64 m_raw = 0;
Expand Down
Loading
Loading