bb: getOccupancy based on index value
This commit is contained in:
1 parent
20f0ea142a
commit
9680d905bd
3 files changed
+21
-1
No files matched your search
+18
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user