stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

commit 16857abdfb0dc9513882aa1ed00e7ffe2776116c
parent b6be584c1ee1da0b25461b87a4e1364554284f96
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon, 19 Sep 2022 21:38:55 +0200

Add Bit Count function

Diffstat:
Msrc/engine.c | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/engine.c b/src/engine.c @@ -25,6 +25,17 @@ const U64 notHFile = C64(0x7f7f7f7f7f7f7f7f); // ~0x8080808080808080 #define bit_set(bitboard, square) ((bitboard) |= C64(1) << (square)) #define bit_pop(bitboard, square) ((bitboard) &= ~(C64(1) << (square))) +static inline int bit_count(U64 bitboard) { + int count = 0; + + while (bitboard > 0) { + count++; + bitboard &= bitboard - 1; + } + + return count; +} + // squares // clang-format off enum enumSquare { @@ -237,5 +248,7 @@ int main(void) { for (int square = 0; square < 64; square++) bitboard_print(mask_bishop_attacks(square)); + + printf("%d\n", bit_count(block)); return 0; }