stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE | |
commit | bbb6134ee38af2a035916cda78f194444add86e7 |
parent | 16857abdfb0dc9513882aa1ed00e7ffe2776116c |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Mon, 19 Sep 2022 19:54:17 +0200 |
Index of the least significant bit function
Diffstat:M | src/engine.c | | | ++++++++++++----- |
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/engine.c b/src/engine.c
@@ -36,6 +36,13 @@ static inline int bit_count(U64 bitboard) {
return count;
}
static inline int bit_lsb_index(U64 bitboard) {
if (!bitboard)
return -1;
return bit_count((bitboard & -bitboard) - 1);
}
// squares
// clang-format off
enum enumSquare {
@@ -49,7 +56,7 @@ enum enumSquare {
a8, b8, c8, d8, e8, f8, g8, h8
};
char squares[][3]={
const char *square_to_coordinates[]={
"a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1",
"a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2",
"a3", "b3", "c3", "d3", "e3", "f3", "g3", "h3",
@@ -246,9 +253,9 @@ int main(void) {
bit_set(block, d4);
bit_set(block, d5);
for (int square = 0; square < 64; square++)
bitboard_print(mask_bishop_attacks(square));
printf("%d\n", bit_count(block));
bitboard_print(block);
bitboard_print((block & -block) - 1);
int cord = bit_lsb_index(block);
printf("%d: %s\n", cord, square_to_coordinates[cord]);
return 0;
}