Added popCount function to bitboards
This commit is contained in:
1 parent
f7d65e8af8
commit
b4bc91ffc2
3 files changed
+17
-3
No files matched your search
@@ -30,6 +30,19 @@ void Bitboard::SetBit(int square) {
|
|||||||
m_board |= (1ULL << 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
|
// Operator overloading for easier comparisons
|
||||||
Bitboard Bitboard::operator&(const Bitboard& other) const {
|
Bitboard Bitboard::operator&(const Bitboard& other) const {
|
||||||
return m_board & other.m_board;
|
return m_board & other.m_board;
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public:
|
|||||||
void SetBit(int square);
|
void SetBit(int square);
|
||||||
void PrintBoard() const;
|
void PrintBoard() const;
|
||||||
|
|
||||||
|
int popCount() const;
|
||||||
|
|
||||||
static Bitboard GetSquare(int square) {
|
static Bitboard GetSquare(int square) {
|
||||||
return (1ULL << square);
|
return (1ULL << square);
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-3
@@ -4,11 +4,10 @@
|
|||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
initLeaperAttacks();
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.Init();
|
board.Init();
|
||||||
|
|
||||||
initLeaperAttacks();
|
|
||||||
rookAttacksOnTheFly(e4, board.occupied).PrintBoard();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user