BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
chess::moves::magics::Bitboard Struct Referencefinal

#include <libchess/board/Bitboard.hpp>

Public Types

using Integer = std::uint64_t

Public Member Functions

constexpr Bitboard () noexcept=default
constexpr Bitboard (Integer val) noexcept
constexpr auto operator== (const Bitboard &) const noexcept -> bool=default
constexpr auto to_int () const noexcept -> Integer
Observers
constexpr auto any () const noexcept -> bool
constexpr auto none () const noexcept -> bool
constexpr auto count () const noexcept -> size_t
constexpr auto test (const Square square) const noexcept -> bool
constexpr auto test (BitboardIndex index) const noexcept -> bool
constexpr auto first () const noexcept -> BitboardIndex
constexpr auto last () const noexcept -> BitboardIndex
Modifiers
constexpr void set (const Square square) noexcept
constexpr void set (BitboardIndex index) noexcept
constexpr void unset (const Square square) noexcept
constexpr void unset (BitboardIndex index) noexcept
constexpr void clear () noexcept
Iteration
constexpr auto indices () const noexcept
constexpr auto squares () const noexcept
constexpr auto subboards () const noexcept
Binary operations
constexpr auto inverse () const noexcept -> Bitboard
constexpr auto operator&= (const Bitboard &other) noexcept -> Bitboard &
constexpr auto operator|= (const Bitboard &other) noexcept -> Bitboard &
constexpr auto operator^= (const Bitboard &other) noexcept -> Bitboard &
constexpr auto operator<<= (size_t num) noexcept -> Bitboard &
constexpr auto operator>>= (size_t num) noexcept -> Bitboard &

Static Public Member Functions

static constexpr auto from_square (Square square) noexcept -> Bitboard

(Note that these are not member symbols.)

consteval auto operator""_bb (const unsigned long long value) noexcept -> Bitboard
constexpr auto operator& (const Bitboard &lhs, const Bitboard &rhs) noexcept -> Bitboard
constexpr auto operator| (const Bitboard &lhs, const Bitboard &rhs) noexcept -> Bitboard
constexpr auto operator^ (const Bitboard &lhs, const Bitboard &rhs) noexcept -> Bitboard
constexpr auto operator<< (const Bitboard &board, size_t num) noexcept -> Bitboard
constexpr auto operator>> (const Bitboard &board, size_t num) noexcept -> Bitboard
auto print_ascii (Bitboard board) -> std::string

Detailed Description

This class is similar to std::bitset, in that it is a simple collection of 64 bits, but it includes some convenience methods specific to usage as a bitboard.

Each bit represents a square of the chessboard; the bit is 1 if there is a piece there, and 0 if the square is empty.

Mapping ranks/files to indices of bits within a bitboard is handled by the Square class.

See also
Pieces, masks

Definition at line 48 of file Bitboard.hpp.

Member Typedef Documentation

◆ Integer

using chess::board::Bitboard::Integer = std::uint64_t

Unsigned integer type used for bitboard representation.

Definition at line 50 of file Bitboard.hpp.

Constructor & Destructor Documentation

◆ Bitboard() [1/2]

chess::board::Bitboard::Bitboard ( )
constexprdefaultnoexcept

Constructs an empty bitboard.

◆ Bitboard() [2/2]

chess::board::Bitboard::Bitboard ( Integer val)
explicitconstexprnoexcept

Constructs a bitboard from an integer representation.

See also
to_int()

Definition at line 274 of file Bitboard.hpp.

Member Function Documentation

◆ any()

auto chess::board::Bitboard::any ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns true if any of the bits are set.

Definition at line 67 of file Bitboard.hpp.

◆ clear()

void chess::board::Bitboard::clear ( )
inlineconstexprnoexcept

Resets all bits to 0.

Definition at line 117 of file Bitboard.hpp.

◆ count()

auto chess::board::Bitboard::count ( ) const -> size_t
inlinenodiscardconstexprnoexcept

Returns the number of bits that are set.

Definition at line 73 of file Bitboard.hpp.

◆ first()

auto chess::board::Bitboard::first ( ) const -> BitboardIndex
nodiscardconstexprnoexcept

Returns the index of the first set bit. This operation may also be known as "bitscan forward". Returns 64 if all bits are 0.

Definition at line 309 of file Bitboard.hpp.

◆ from_square()

auto chess::board::Bitboard::from_square ( Square square) -> Bitboard
staticnodiscardconstexprnoexcept

Returns a bitboard with only a single bit set.

Definition at line 279 of file Bitboard.hpp.

◆ indices()

auto chess::board::Bitboard::indices ( ) const
nodiscardconstexprnoexcept

Returns an iterable range of indices representing the 1 bits in this bitboard. The returned indices should be iterated by value, not by reference; i.e.:

for (auto index : board.indices())
; // ...
See also
squares(), subboards()

Definition at line 452 of file Bitboard.hpp.

◆ inverse()

auto chess::board::Bitboard::inverse ( ) const -> Bitboard
nodiscardconstexprnoexcept

Returns a copy of this bitboard with all bits flipped (binary NOT).

Definition at line 357 of file Bitboard.hpp.

◆ last()

auto chess::board::Bitboard::last ( ) const -> BitboardIndex
nodiscardconstexprnoexcept

Returns the index of the last set bit. This operation may also be known as "bitscan reverse". Returns 64 if all bits are 0.

Definition at line 315 of file Bitboard.hpp.

◆ none()

auto chess::board::Bitboard::none ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns true if none of the bits are set.

Definition at line 70 of file Bitboard.hpp.

◆ operator&=()

auto chess::board::Bitboard::operator&= ( const Bitboard & other) -> Bitboard &
constexprnoexcept

Performs binary AND with another bitboard.

Definition at line 327 of file Bitboard.hpp.

◆ operator<<=()

auto chess::board::Bitboard::operator<<= ( size_t num) -> Bitboard &
constexprnoexcept

Performs binary shift left (towards higher index positions). Zeroes are shifted in, and bits that would go to an index out of range are dropped.

Definition at line 345 of file Bitboard.hpp.

◆ operator==()

auto chess::board::Bitboard::operator== ( const Bitboard & ) const -> bool=default
nodiscardconstexprdefaultnoexcept

Returns true if the two bitboards have all the same bits set.

◆ operator>>=()

auto chess::board::Bitboard::operator>>= ( size_t num) -> Bitboard &
constexprnoexcept

Performs binary shift right (towards lower index positions). Zeroes are shifted in, and bits that would go to an index out of range are dropped.

Definition at line 351 of file Bitboard.hpp.

◆ operator^=()

auto chess::board::Bitboard::operator^= ( const Bitboard & other) -> Bitboard &
constexprnoexcept

Performs binary XOR with another bitboard.

Definition at line 339 of file Bitboard.hpp.

◆ operator|=()

auto chess::board::Bitboard::operator|= ( const Bitboard & other) -> Bitboard &
constexprnoexcept

Performs binary OR with another bitboard.

Definition at line 333 of file Bitboard.hpp.

◆ set() [1/2]

void chess::board::Bitboard::set ( BitboardIndex index)
constexprnoexcept

Sets the given square's bit to 1. This method asserts if the given index is greater than 63.

Definition at line 293 of file Bitboard.hpp.

◆ set() [2/2]

void chess::board::Bitboard::set ( const Square square)
inlineconstexprnoexcept

Sets the given square's bit to 1.

Definition at line 101 of file Bitboard.hpp.

◆ squares()

auto chess::board::Bitboard::squares ( ) const
nodiscardconstexprnoexcept

Returns an iterable range of Square objects representing the 1 bits in this bitboard. The Square objects should be iterated by value, not by reference; i.e.:

for (auto square : board.squares())
; // ...
See also
indices(), subboards()

Definition at line 461 of file Bitboard.hpp.

◆ subboards()

auto chess::board::Bitboard::subboards ( ) const
nodiscardconstexprnoexcept

Returns an iterable range of Bitboard objects that each have a single bit set, each representing the 1 bits in this bitboard. This is a transformation of a single bitboard with up to 64 bits set into a set of up to 64 bitboards each with a single bit set.

The Bitboard objects should be iterated by value, not by reference; i.e.:

for (auto subboard : board.subboards())
; // ...
See also
indices(), squares()

Definition at line 467 of file Bitboard.hpp.

◆ test() [1/2]

auto chess::board::Bitboard::test ( BitboardIndex index) const -> bool
nodiscardconstexprnoexcept

Returns true if there is a piece on the given square. This method asserts if the given index is greater than 63.

Definition at line 284 of file Bitboard.hpp.

◆ test() [2/2]

auto chess::board::Bitboard::test ( const Square square) const -> bool
inlinenodiscardconstexprnoexcept

Returns true if there is a piece on the given square.

Definition at line 76 of file Bitboard.hpp.

◆ to_int()

auto chess::board::Bitboard::to_int ( ) const -> Integer
inlinenodiscardconstexprnoexcept

Converts this bitboard to its integer representation.

Definition at line 122 of file Bitboard.hpp.

◆ unset() [1/2]

void chess::board::Bitboard::unset ( BitboardIndex index)
constexprnoexcept

Sets the given square's bit to 0. This method asserts if the given index is greater than 63.

Definition at line 300 of file Bitboard.hpp.

◆ unset() [2/2]

void chess::board::Bitboard::unset ( const Square square)
inlineconstexprnoexcept

Sets the given square's bit to 0.

Definition at line 109 of file Bitboard.hpp.


The documentation for this struct was generated from the following file: