BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
Moves
Collaboration diagram for Moves:

Files

file  Attacks.hpp
file  Magics.hpp
file  Move.hpp
file  MoveGen.hpp
file  Patterns.hpp
file  Perft.hpp
file  PseudoLegal.hpp

Namespaces

namespace  chess
namespace  chess::moves
namespace  chess::moves::magics
namespace  chess::moves::patterns
namespace  chess::moves::pseudo_legal

Classes

struct  chess::moves::Move
struct  chess::moves::PerftResult

Functions

template<Color Side>
constexpr auto chess::moves::num_squares_attacked (const Pieces &pieces, Bitboard targetSquares, Bitboard enemyPieces, bool includeKing=true) noexcept -> size_t
constexpr auto operator<=> (const Move &first, const Move &second) noexcept -> std::strong_ordering
template<bool IsRoot = true>
auto perft (size_t depth, const game::Position &startingPosition) -> PerftResult
template<Color Side>
constexpr auto chess::moves::squares_attacked (const Pieces &pieces, Bitboard targetSquares, Bitboard enemyPieces) noexcept -> bool
constexpr auto chess::moves::MAX_MOVES = 256uz
auto chess::moves::magics::bishop (Square bishopPos, Bitboard occupiedSquares, Bitboard friendlyPieces) -> Bitboard
auto chess::moves::magics::rook (Square rookPos, Bitboard occupiedSquares, Bitboard friendlyPieces) -> Bitboard
auto chess::moves::magics::queen (Square queenPos, Bitboard occupiedSquares, Bitboard friendlyPieces) -> Bitboard
template<Color Side>
constexpr auto chess::moves::patterns::pawn_pushes (Bitboard starting) noexcept -> Bitboard
template<Color Side>
constexpr auto chess::moves::patterns::pawn_double_pushes (Bitboard starting) noexcept -> Bitboard
template<Color Side>
constexpr auto chess::moves::patterns::pawn_attacks (Bitboard starting) noexcept -> Bitboard
constexpr auto chess::moves::patterns::knight (Bitboard starting) noexcept -> Bitboard
constexpr auto chess::moves::patterns::bishop (Bitboard starting) noexcept -> Bitboard
constexpr auto chess::moves::patterns::rook (Bitboard starting) noexcept -> Bitboard
constexpr auto chess::moves::patterns::queen (Bitboard starting) noexcept -> Bitboard
constexpr auto chess::moves::patterns::king (Bitboard starting) noexcept -> Bitboard
template<Color Side>
constexpr auto chess::moves::pseudo_legal::pawn_pushes (Bitboard startingPawns, Bitboard emptySquares) noexcept -> Bitboard
template<Color Side>
constexpr auto chess::moves::pseudo_legal::pawn_double_pushes (Bitboard startingPawns, Bitboard occupiedSquares) noexcept -> Bitboard
template<Color Side>
constexpr auto chess::moves::pseudo_legal::pawn_captures (Bitboard startingPawns, Bitboard enemyPieces) noexcept -> Bitboard
constexpr auto chess::moves::pseudo_legal::knight (Bitboard startingKnights, Bitboard friendlyPieces) noexcept -> Bitboard
constexpr auto chess::moves::pseudo_legal::bishop (Bitboard startingBishops, Bitboard emptySquares, Bitboard friendlyPieces) noexcept -> Bitboard
constexpr auto chess::moves::pseudo_legal::rook (Bitboard startingRooks, Bitboard emptySquares, Bitboard friendlyPieces) noexcept -> Bitboard
constexpr auto chess::moves::pseudo_legal::queen (Bitboard startingQueens, Bitboard emptySquares, Bitboard friendlyPieces) noexcept -> Bitboard
constexpr auto chess::moves::pseudo_legal::king (Bitboard startingKing, Bitboard friendlyPieces) noexcept -> Bitboard
constexpr auto castle_kingside (Color color) noexcept -> Move
constexpr auto castle_queenside (Color color) noexcept -> Move
constexpr auto promotion (File file, Color color, PieceType promotedType=PieceType::Queen) noexcept -> Move
constexpr auto castle_queenside (Color color) noexcept -> Move
constexpr auto promotion (File file, Color color, PieceType promotedType=PieceType::Queen) noexcept -> Move
constexpr auto castle_queenside (Color color) noexcept -> Move
constexpr auto promotion (File file, Color color, PieceType promotedType=PieceType::Queen) noexcept -> Move
constexpr auto castle_queenside (Color color) noexcept -> Move
constexpr auto promotion (File file, Color color, PieceType promotedType=PieceType::Queen) noexcept -> Move
constexpr auto castle_queenside (Color color) noexcept -> Move
constexpr auto promotion (File file, Color color, PieceType promotedType=PieceType::Queen) noexcept -> Move
constexpr auto castle_queenside (Color color) noexcept -> Move
constexpr auto promotion (File file, Color color, PieceType promotedType=PieceType::Queen) noexcept -> Move

Detailed Description

Classes for modeling moves. In the search tree, positions are nodes and moves are edges between them.

Function Documentation

◆ bishop() [1/3]

auto chess::moves::magics::bishop ( Square bishopPos,
Bitboard occupiedSquares,
Bitboard friendlyPieces ) -> Bitboard
nodiscard

Calculates all pseudo-legal bishop moves.

The returned move set includes possible captures (i.e., rays ending where an enemy piece is located), and also considers blocking friendly pieces.

◆ bishop() [2/3]

auto chess::moves::patterns::bishop ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all possible bishop moves from the given starting square.

Definition at line 152 of file Patterns.hpp.

◆ bishop() [3/3]

auto chess::moves::pseudo_legal::bishop ( Bitboard startingBishops,
Bitboard emptySquares,
Bitboard friendlyPieces ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal bishop moves.

The returned move set includes possible captures (i.e., rays ending where an enemy piece is located), and also considers blocking friendly pieces.

Definition at line 328 of file PseudoLegal.hpp.

◆ castle_kingside()

auto castle_kingside ( Color color) -> Move
related

Creates a move encoding kingside ("short") castling for the given color.

See also
castle_queenside()

Definition at line 304 of file Move.hpp.

◆ castle_queenside() [1/6]

auto castle_queenside ( Color color) -> Move
related

Creates a move encoding queenside ("long") castling for the given color.

See also
castle_kingside()

Definition at line 315 of file Move.hpp.

◆ castle_queenside() [2/6]

auto castle_queenside ( Color color) -> Move
related

Creates a move encoding queenside ("long") castling for the given color.

See also
castle_kingside()

Definition at line 315 of file Move.hpp.

◆ castle_queenside() [3/6]

auto castle_queenside ( Color color) -> Move
related

Creates a move encoding queenside ("long") castling for the given color.

See also
castle_kingside()

Definition at line 315 of file Move.hpp.

◆ castle_queenside() [4/6]

auto castle_queenside ( Color color) -> Move
related

Creates a move encoding queenside ("long") castling for the given color.

See also
castle_kingside()

Definition at line 315 of file Move.hpp.

◆ castle_queenside() [5/6]

auto castle_queenside ( Color color) -> Move
related

Creates a move encoding queenside ("long") castling for the given color.

See also
castle_kingside()

Definition at line 315 of file Move.hpp.

◆ castle_queenside() [6/6]

auto castle_queenside ( Color color) -> Move
related

Creates a move encoding queenside ("long") castling for the given color.

See also
castle_kingside()

Definition at line 315 of file Move.hpp.

◆ king() [1/2]

auto chess::moves::patterns::king ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all possible king moves from the given starting position. Typically the starting bitboard will have only a single bit set, but this method can technically calculate moves for both kings at once, if both of their positions are set in the bitboard sent to this function.

Definition at line 181 of file Patterns.hpp.

◆ king() [2/2]

auto chess::moves::pseudo_legal::king ( Bitboard startingKing,
Bitboard friendlyPieces ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal king moves.

Definition at line 163 of file PseudoLegal.hpp.

◆ knight() [1/2]

auto chess::moves::patterns::knight ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all possible knight moves from the given starting position.

Definition at line 128 of file Patterns.hpp.

◆ knight() [2/2]

auto chess::moves::pseudo_legal::knight ( Bitboard startingKnights,
Bitboard friendlyPieces ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal knight moves.

Definition at line 156 of file PseudoLegal.hpp.

◆ num_squares_attacked()

template<Color Side>
auto chess::moves::num_squares_attacked ( const Pieces & pieces,
Bitboard targetSquares,
Bitboard enemyPieces,
bool includeKing = true ) -> size_t
nodiscardconstexprnoexcept

Returns the number of targetSquares that any of the pieces attack. This function considers only pseudo-legal moves, not strictly legal moves. King attacks will only be considered if includeKing is true.

Template Parameters
SideThe color that the pieces represent.
See also
squares_attacked()

Definition at line 131 of file Attacks.hpp.

◆ operator<=>()

auto operator<=> ( const Move & first,
const Move & second ) -> std::strong_ordering
related

Provides a strong ordering of moves. This can be useful for sorting lists of moves.

Definition at line 145 of file Move.hpp.

◆ pawn_attacks()

template<Color Side>
auto chess::moves::patterns::pawn_attacks ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all squares that are attacked by pawns from the given starting position and color. This can be used to calculate possible pawn captures.

Definition at line 120 of file Patterns.hpp.

◆ pawn_captures()

template<Color Side>
auto chess::moves::pseudo_legal::pawn_captures ( Bitboard startingPawns,
Bitboard enemyPieces ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal pawn captures. The returned bitboard has 1 bits set where each pawn would land after making a capture. Note that this function does not generate possible en passant captures.

Definition at line 149 of file PseudoLegal.hpp.

◆ pawn_double_pushes() [1/2]

template<Color Side>
auto chess::moves::patterns::pawn_double_pushes ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all possible pawn double pushes for the given starting position and color.

Definition at line 105 of file Patterns.hpp.

◆ pawn_double_pushes() [2/2]

template<Color Side>
auto chess::moves::pseudo_legal::pawn_double_pushes ( Bitboard startingPawns,
Bitboard occupiedSquares ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal pawn double pushes.

Definition at line 132 of file PseudoLegal.hpp.

◆ pawn_pushes() [1/2]

template<Color Side>
auto chess::moves::patterns::pawn_pushes ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all possible pawn pushes for the given starting position and color.

Definition at line 98 of file Patterns.hpp.

◆ pawn_pushes() [2/2]

template<Color Side>
auto chess::moves::pseudo_legal::pawn_pushes ( Bitboard startingPawns,
Bitboard emptySquares ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal pawn pushes.

Definition at line 124 of file PseudoLegal.hpp.

◆ perft()

template<bool IsRoot = true>
auto perft ( size_t depth,
const game::Position & startingPosition ) -> PerftResult
related

Computes perft of the given position.

Definition at line 119 of file Perft.hpp.

◆ promotion() [1/6]

auto promotion ( File file,
Color color,
PieceType promotedType = PieceType::Queen ) -> Move
related

Creates a move encoding a pawn promotion. This function creates simple promotions that don't involve captures.

Definition at line 326 of file Move.hpp.

◆ promotion() [2/6]

auto promotion ( File file,
Color color,
PieceType promotedType = PieceType::Queen ) -> Move
related

Creates a move encoding a pawn promotion. This function creates simple promotions that don't involve captures.

Definition at line 326 of file Move.hpp.

◆ promotion() [3/6]

auto promotion ( File file,
Color color,
PieceType promotedType = PieceType::Queen ) -> Move
related

Creates a move encoding a pawn promotion. This function creates simple promotions that don't involve captures.

Definition at line 326 of file Move.hpp.

◆ promotion() [4/6]

auto promotion ( File file,
Color color,
PieceType promotedType = PieceType::Queen ) -> Move
related

Creates a move encoding a pawn promotion. This function creates simple promotions that don't involve captures.

Definition at line 326 of file Move.hpp.

◆ promotion() [5/6]

auto promotion ( File file,
Color color,
PieceType promotedType = PieceType::Queen ) -> Move
related

Creates a move encoding a pawn promotion. This function creates simple promotions that don't involve captures.

Definition at line 326 of file Move.hpp.

◆ promotion() [6/6]

auto promotion ( File file,
Color color,
PieceType promotedType = PieceType::Queen ) -> Move
related

Creates a move encoding a pawn promotion. This function creates simple promotions that don't involve captures.

Definition at line 326 of file Move.hpp.

◆ queen() [1/3]

auto chess::moves::magics::queen ( Square queenPos,
Bitboard occupiedSquares,
Bitboard friendlyPieces ) -> Bitboard
nodiscard

Calculates all pseudo-legal queen moves.

The returned move set includes possible captures (i.e., rays ending where an enemy piece is located), and also considers blocking friendly pieces.

◆ queen() [2/3]

auto chess::moves::patterns::queen ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all possible queen moves from the given starting square.

Definition at line 170 of file Patterns.hpp.

◆ queen() [3/3]

auto chess::moves::pseudo_legal::queen ( Bitboard startingQueens,
Bitboard emptySquares,
Bitboard friendlyPieces ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal queen moves, taking blocking pieces into consideration.

The returned move set includes possible captures (i.e., rays ending where an enemy piece is located), and also considers blocking friendly pieces.

Definition at line 335 of file PseudoLegal.hpp.

◆ rook() [1/3]

auto chess::moves::magics::rook ( Square rookPos,
Bitboard occupiedSquares,
Bitboard friendlyPieces ) -> Bitboard
nodiscard

Calculates all pseudo-legal rook moves.

The returned move set includes possible captures (i.e., rays ending where an enemy piece is located), and also considers blocking friendly pieces.

◆ rook() [2/3]

auto chess::moves::patterns::rook ( Bitboard starting) -> Bitboard
nodiscardconstexprnoexcept

Calculates all possible rook moves from the given starting square.

Definition at line 161 of file Patterns.hpp.

◆ rook() [3/3]

auto chess::moves::pseudo_legal::rook ( Bitboard startingRooks,
Bitboard emptySquares,
Bitboard friendlyPieces ) -> Bitboard
nodiscardconstexprnoexcept

Calculates all pseudo-legal rook moves, taking blocking pieces into consideration.

The returned move set includes possible captures (i.e., rays ending where an enemy piece is located), and also considers blocking friendly pieces.

Definition at line 321 of file PseudoLegal.hpp.

◆ squares_attacked()

template<Color Side>
auto chess::moves::squares_attacked ( const Pieces & pieces,
Bitboard targetSquares,
Bitboard enemyPieces ) -> bool
nodiscardconstexprnoexcept

Returns true if any of the pieces attacks any of the targetSquares. This function considers only pseudo-legal moves, not strictly legal moves.

Template Parameters
SideThe color that the pieces represent.
See also
num_squares_attacked()

Definition at line 81 of file Attacks.hpp.

Variable Documentation

◆ MAX_MOVES

auto chess::moves::MAX_MOVES = 256uz
inlineconstexpr

The maximum number of moves that can be generated for a position. The actual maximum number of legal moves for any known position is 218, for the position R6R/3Q4/1Q4Q1/4Q3/2Q4Q/Q4Q2/pp1Q4/kBNN1KB1 w - - 0 1.

See also
MoveList

Definition at line 58 of file MoveGen.hpp.