bb: getOccupancy based on index value

This commit is contained in:
rektdie committed 2024-03-11 23:23:52 +01:00
1 parent 20f0ea142a
commit 9680d905bd
3 files changed
+21 -1

No files matched your search

+18 -1
View File
@@ -49,7 +49,7 @@ int Bitboard::popCount() const {
return count;
}
// LS1B = least significat first bit
// LS1B = least significant first bit
int Bitboard::getLS1BIndex() const {
if (m_board) {
// count trailing bits before LS1B
@@ -59,6 +59,23 @@ int Bitboard::getLS1BIndex() const {
return -1;
}
Bitboard Bitboard::getOccupancy(int index, Bitboard attackMask) {
Bitboard occupancy;
int squareNum = attackMask.popCount();
for (int count = 0; count < squareNum; count++) {
int square = attackMask.getLS1BIndex();
attackMask.PopBit(square);
if (index & (1 << count)) {
occupancy |= (1ULL << square);
}
}
return occupancy;
}
// Operator overloading for easier comparisons
Bitboard Bitboard::operator&(const Bitboard& other) const {
return m_board & other.m_board;
+1
View File
@@ -20,6 +20,7 @@ public:
int popCount() const;
int getLS1BIndex() const;
static Bitboard getOccupancy(int index, Bitboard attackMask);
static Bitboard GetSquare(int square) {
return (1ULL << square);
+2
View File
@@ -9,5 +9,7 @@ int main() {
Board board;
board.Init();
Bitboard::getOccupancy(4095, maskRookAttacks(e5)).PrintBoard();
return 0;
}