Files
cpl_cpp-project/BitBoard.cpp

34 lines
852 B
C++

#include "BitBoard.h"
BitBoard::BitBoard(uint64_t v) {
mBoard = v;
}
std::ostream &operator<<(std::ostream &os, const BitBoard &board) {
// For debugging only, performance isn't important
for (int i = 7; i >= 0; i--) {
int rank = i * 8;
for (int j = 0; j < 8; j++) {
// Get the piece for this index. Assume it exists.
// Print piece, otherwise '.';
if (board.mBoard & (1ULL << (rank + j))) {
os << 1;
} else {
os << '.';
}
os << ' ';
}
os << '\n';
}
return os;
}
BitBoard BitBoard::getRank(int r) {
return (genShift(1ULL, (r + 1) * 8) - 1) & genShift(~1ULL, r * 8 - 1);
}
BitBoard BitBoard::genShift(BitBoard x, const int s) {
return (s < 0) ? (x >> -s) : (s > 63) ? x : (x << s);
}