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;
+2
View File
@@ -17,6 +17,8 @@ public:
void SetBit(int square);
void PrintBoard() const;
int popCount() const;
static Bitboard GetSquare(int square) {
return (1ULL << square);
};
+2 -3
View File
@@ -4,11 +4,10 @@
#include "movegen.h"
int main() {
initLeaperAttacks();
Board board;
board.Init();
initLeaperAttacks();
rookAttacksOnTheFly(e4, board.occupied).PrintBoard();
return 0;
}