Added function to bb: getting least significant 1st bit index
This commit is contained in:
1 parent
b4bc91ffc2
commit
13c7bcc092
3 files changed
+23
-1
No files matched your search
@@ -43,6 +43,16 @@ int Bitboard::popCount() const {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LS1B = least significat first bit
|
||||||
|
int Bitboard::getLS1BIndex() const {
|
||||||
|
if (m_board) {
|
||||||
|
// count trailing bits before LS1B
|
||||||
|
return Bitboard((m_board & -m_board) - 1).popCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public:
|
|||||||
void PrintBoard() const;
|
void PrintBoard() const;
|
||||||
|
|
||||||
int popCount() const;
|
int popCount() const;
|
||||||
|
int getLS1BIndex() const;
|
||||||
|
|
||||||
static Bitboard GetSquare(int square) {
|
static Bitboard GetSquare(int square) {
|
||||||
return (1ULL << square);
|
return (1ULL << square);
|
||||||
|
|||||||
+12
-1
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using U64 = uint64_t;
|
using U64 = uint64_t;
|
||||||
|
|
||||||
constexpr char StartingFen[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
constexpr char StartingFen[] = "8/1BR1P1P1/2Q1p3/1P2P2p/3B1K2/3k4/3p2pP/4n3 w - - 0 1";
|
||||||
|
|
||||||
enum COLOR {
|
enum COLOR {
|
||||||
White,
|
White,
|
||||||
@@ -56,6 +56,17 @@ enum SQUARE {
|
|||||||
a8, b8, c8, d8, e8, f8, g8, h8
|
a8, b8, c8, d8, e8, f8, g8, h8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr std::array<const char*, 64> squareCoords = {
|
||||||
|
"a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1",
|
||||||
|
"a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2",
|
||||||
|
"a3", "b3", "c3", "d3", "e3", "f3", "g3", "h3",
|
||||||
|
"a4", "b4", "c4", "d4", "e4", "f4", "g4", "h4",
|
||||||
|
"a5", "b5", "c5", "d5", "e5", "f5", "g5", "h5",
|
||||||
|
"a6", "b6", "c6", "d6", "e6", "f6", "g6", "h6",
|
||||||
|
"a7", "b7", "c7", "d7", "e7", "f7", "g7", "h7",
|
||||||
|
"a8", "b8", "c8", "d8", "e8", "f8", "g8", "h8"
|
||||||
|
};
|
||||||
|
|
||||||
enum DIRECTION {
|
enum DIRECTION {
|
||||||
north = 8,
|
north = 8,
|
||||||
east = 1,
|
east = 1,
|
||||||
|
|||||||
Reference in new issue
Block a user