Added popCount function to bitboards

This commit is contained in:
rektdie committed 2024-03-03 21:28:39 +01:00
1 parent f7d65e8af8
commit b4bc91ffc2
3 files changed
+17 -3

No files matched your search

+13
View File
@@ -30,6 +30,19 @@ void Bitboard::SetBit(int square) {
m_board |= (1ULL << square);
}
int Bitboard::popCount() const {
U64 board = m_board;
int count = 0;
while (board) {
board &= board - 1;
count++;
}
return count;
}
// Operator overloading for easier comparisons
Bitboard Bitboard::operator&(const Bitboard& other) const {
return m_board & other.m_board;