BitBully 0.0.78
A fast, perfect-play Connect-4 engine in modern C++
Loading...
Searching...
No Matches
Board.h File Reference

Bitboard-based representation of a Connect-4 position. More...

#include <array>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <random>
#include <sstream>
#include <vector>
#include "MoveList.h"
Include dependency graph for Board.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  BitBully::Board
 Connect-4 position represented as a pair of 64-bit bitboards. More...
struct  BitBully::Board::RawState
 Plain-data snapshot of the board's internal state. More...

Namespaces

namespace  BitBully
 Top-level namespace for the BitBully Connect-4 engine.

Macros

#define uint64_t_popcnt   popCountBoard
 Portable fallback popcount when no compiler intrinsic is available.

Functions

int ctz_u64 (uint64_t x)
 Count trailing zero bits of a 64-bit integer.
std::vector< int > bits_set (uint64_t x)
 Decompose a bitboard into the indices of its set bits.

Variables

constexpr int BitBully::CHAR_BIT = 8
 Number of bits per byte (defined locally if not provided by the platform).

Detailed Description

Bitboard-based representation of a Connect-4 position.

Defines the BitBully::Board class together with a handful of compile-time helpers (bit masks, popcount, count-trailing-zeros) used by the solver. The encoding follows the "split bitboard" scheme made popular by John Tromp's Fhourstones: a single 64-bit word holds all occupied cells of a 7×6 grid, plus an extra "sentinel" row that is never set during play but is used to detect overflowing column appends in constant time.

See also
https://github.com/qu1j0t3/fhourstones

Definition in file Board.h.

Macro Definition Documentation

◆ uint64_t_popcnt

#define uint64_t_popcnt   popCountBoard

Portable fallback popcount when no compiler intrinsic is available.

Definition at line 50 of file Board.h.

Function Documentation

◆ bits_set()

std::vector< int > bits_set ( uint64_t x)
inline

Decompose a bitboard into the indices of its set bits.

Walks the input from the least to the most significant bit, clearing one bit at a time using x &= x - 1. The result is sorted in ascending bit order.

Parameters
xBitboard whose set bits should be enumerated.
Returns
Vector of bit indices (0…63), one per set bit in x.

Definition at line 93 of file Board.h.

Here is the call graph for this function:

◆ ctz_u64()

int ctz_u64 ( uint64_t x)
inline

Count trailing zero bits of a 64-bit integer.

Returns the bit index of the least significant set bit. The function uses the most efficient implementation available for the current toolchain (_BitScanForward64 on MSVC, __builtin_ctzll on GCC/Clang) and falls back to a portable loop otherwise.

Parameters
xNon-zero 64-bit input. Calling with x == 0 is undefined for the intrinsic variants.
Returns
Zero-based index of the least significant set bit.

Definition at line 66 of file Board.h.

Here is the caller graph for this function: