Chess Engine
C++ chess engine with movegen, bitboards, and Arduino-friendly docs
Loading...
Searching...
No Matches
bitboards.cpp File Reference
#include "stdio.h"
#include "defs.h"
#include "setup.h"
Include dependency graph for bitboards.cpp:

Go to the source code of this file.

Functions

int popLSB (U64 *bb)
 Pops the least significant 1-bit from a bitboard and returns its index (0–63).
int countSetBits (U64 b)
 Counts the number of 1-bits in a bitboard.
void printBitBoard (U64 bb)
 Prints a visual representation of a bitboard to stdout.

Variables

const int BitTable [64]
 Lookup table for bit index extraction.

Function Documentation

◆ countSetBits()

int countSetBits ( U64 b)

Counts the number of 1-bits in a bitboard.

Parameters
bBitboard value.
Returns
Number of set bits.

Definition at line 21 of file bitboards.cpp.

◆ popLSB()

int popLSB ( U64 * bb)

Pops the least significant 1-bit from a bitboard and returns its index (0–63).

Parameters
bbPointer to the bitboard to modify.
Returns
Index (0–63) of the popped bit.

Definition at line 14 of file bitboards.cpp.

References BitTable.

◆ printBitBoard()

void printBitBoard ( U64 bb)

Prints a visual representation of a bitboard to stdout.

'X' marks set bits, '-' marks unset bits.

Parameters
bbBitboard to print.

Definition at line 27 of file bitboards.cpp.

References FILE_A, FILE_H, FR2SQ, RANK_1, RANK_8, and SQ64.

Variable Documentation

◆ BitTable

const int BitTable[64]
Initial value:
= {
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
58, 20, 37, 17, 36, 8
}

Lookup table for bit index extraction.

Definition at line 7 of file bitboards.cpp.

Referenced by popLSB().