From 13c7bcc0923bcc17d35acdcff9cd479607a1b535 Mon Sep 17 00:00:00 2001 From: "rektdie@gmail.com" Date: Sun, 3 Mar 2024 22:19:02 +0100 Subject: [PATCH] Added function to bb: getting least significant 1st bit index --- source/bitboards.cpp | 10 ++++++++++ source/bitboards.h | 1 + source/types.h | 13 ++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/source/bitboards.cpp b/source/bitboards.cpp index 7867165..748f72c 100644 --- a/source/bitboards.cpp +++ b/source/bitboards.cpp @@ -43,6 +43,16 @@ int Bitboard::popCount() const { 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 Bitboard Bitboard::operator&(const Bitboard& other) const { return m_board & other.m_board; diff --git a/source/bitboards.h b/source/bitboards.h index 9b3a17b..5c303a6 100644 --- a/source/bitboards.h +++ b/source/bitboards.h @@ -18,6 +18,7 @@ public: void PrintBoard() const; int popCount() const; + int getLS1BIndex() const; static Bitboard GetSquare(int square) { return (1ULL << square); diff --git a/source/types.h b/source/types.h index a86fdb3..1d5062b 100644 --- a/source/types.h +++ b/source/types.h @@ -4,7 +4,7 @@ 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 { White, @@ -56,6 +56,17 @@ enum SQUARE { a8, b8, c8, d8, e8, f8, g8, h8 }; +constexpr std::array 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 { north = 8, east = 1,