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

#include <libchess/board/Pieces.hpp>

Collaboration diagram for chess::moves::Pieces:

Public Member Functions

consteval Pieces () noexcept=default
constexpr Pieces (Color color) noexcept
constexpr void capture_at (Square square) noexcept
constexpr auto free () const noexcept -> Bitboard
constexpr auto get_king_location () const noexcept -> Square
constexpr auto get_piece_on (Square square) const noexcept -> std::optional< PieceType >
constexpr auto get_type (PieceType type) const noexcept -> Bitboard
constexpr auto get_type (PieceType type) noexcept -> Bitboard &
constexpr auto has_bishop_pair () const noexcept -> bool
constexpr auto is_file_half_open (File file) const noexcept -> bool
constexpr auto operator== (const Pieces &) const noexcept -> bool=default
constexpr void our_move (moves::Move move, Color ourColor) noexcept
constexpr void refresh_occupied () noexcept
constexpr void vertical_flip () noexcept

Public Attributes

Bitboard bishops
Bitboard king
Bitboard knights
Bitboard occupied
Bitboard pawns
Bitboard queens
Bitboard rooks

Detailed Description

This class encapsulates a bitboard for each piece type. An instance of this class encodes the locations of all pieces for one side.

Invariant
No more than one piece type may occupy a given square; that is, each bitboard index will only have its bit set in at most one of the piece type bitboards.

Definition at line 49 of file Pieces.hpp.

Constructor & Destructor Documentation

◆ Pieces() [1/2]

chess::board::Pieces::Pieces ( Color color)
explicitconstexprnoexcept

Creates a Pieces object encoding the starting position for the given side.

Definition at line 148 of file Pieces.hpp.

◆ Pieces() [2/2]

chess::board::Pieces::Pieces ( )
constevaldefaultnoexcept

Creates an empty Pieces object with none of its bitboards initialized.

Member Function Documentation

◆ capture_at()

void chess::board::Pieces::capture_at ( Square square)
constexprnoexcept

Removes the piece on the given square, if any. This method asserts if the square is the location of the king.

Definition at line 251 of file Pieces.hpp.

◆ free()

auto chess::board::Pieces::free ( ) const -> Bitboard
inlinenodiscardconstexprnoexcept

Returns a bitboard that is the inverse of the bitboard returned by occupied(). The returned bitboard has a bit set if no piece of any type is on that square.

Definition at line 98 of file Pieces.hpp.

◆ get_king_location()

auto chess::board::Pieces::get_king_location ( ) const -> Square
nodiscardconstexprnoexcept

Returns the location of the king.

Definition at line 219 of file Pieces.hpp.

◆ get_piece_on()

auto chess::board::Pieces::get_piece_on ( Square square) const -> std::optional< PieceType >
nodiscardconstexprnoexcept

Returns the type of the piece on the given square, or nullopt if the square is empty. Note that libchess's bitboard board representation is not optimized for this operation.

Definition at line 226 of file Pieces.hpp.

◆ get_type() [1/2]

auto chess::board::Pieces::get_type ( PieceType type) const -> Bitboard
nodiscardconstexprnoexcept

Returns the bitboard corresponding to the given piece type.

Definition at line 191 of file Pieces.hpp.

◆ get_type() [2/2]

auto chess::board::Pieces::get_type ( PieceType type) -> Bitboard &
nodiscardconstexprnoexcept

Returns the bitboard corresponding to the given piece type.

Definition at line 177 of file Pieces.hpp.

◆ has_bishop_pair()

auto chess::board::Pieces::has_bishop_pair ( ) const -> bool
nodiscardconstexprnoexcept

Returns true if this side has at least one bishop on each color complex.

Definition at line 210 of file Pieces.hpp.

◆ is_file_half_open()

auto chess::board::Pieces::is_file_half_open ( File file) const -> bool
nodiscardconstexprnoexcept

Returns true if there are no pawns of this color anywhere on the given file.

Definition at line 205 of file Pieces.hpp.

◆ operator==()

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

Returns true if the two piece sets are identical.

◆ our_move()

void chess::board::Pieces::our_move ( moves::Move move,
Color ourColor )
constexprnoexcept

Call this when a move is made by this side to update the piece bitboards.

Definition at line 267 of file Pieces.hpp.

◆ refresh_occupied()

void chess::board::Pieces::refresh_occupied ( )
constexprnoexcept

Recalculates the occupied bitboard from each of the piece bitboards.

Definition at line 158 of file Pieces.hpp.

◆ vertical_flip()

void chess::board::Pieces::vertical_flip ( )
constexprnoexcept

Performs a vertical flip of all piece bitboards and refreshes the occupied bitboard.

Definition at line 163 of file Pieces.hpp.

Member Data Documentation

◆ bishops

This bitboard holds the locations of this side's bishops.

Definition at line 63 of file Pieces.hpp.

◆ king

This bitboard holds the locations of this side's king.

Invariant
This board will never have more than a single bit set.

Definition at line 75 of file Pieces.hpp.

◆ knights

This bitboard holds the locations of this side's knights.

Definition at line 60 of file Pieces.hpp.

◆ occupied

Initial value:

This bitboard is a composite of all of this side's pieces. This board is kept up to date by the capture_at() and our_move() methods. If you update the individual piece boards manually, you must also update this board, or call refresh_occupied() to flush and repopulate it.

Definition at line 82 of file Pieces.hpp.

◆ pawns

This bitboard holds the locations of this side's pawns.

Definition at line 57 of file Pieces.hpp.

◆ queens

This bitboard holds the locations of this side's queens.

Definition at line 69 of file Pieces.hpp.

◆ rooks

This bitboard holds the locations of this side's rooks.

Definition at line 66 of file Pieces.hpp.


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