BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
chess::uci::printing::Move Struct Referencefinal

#include <libchess/moves/Move.hpp>

Public Member Functions

constexpr Move ()=default
constexpr Move (Square start, Square end, PieceType type, MaybePieceType promotedType=std::nullopt)
constexpr auto from () const noexcept -> Square
constexpr auto hash () const noexcept -> size_t
constexpr auto is_castling () const noexcept -> bool
auto is_null () const noexcept -> bool
constexpr auto is_promotion () const noexcept -> bool
constexpr auto is_under_promotion () const noexcept -> bool
constexpr auto operator== (const Move &) const noexcept -> bool=default
constexpr auto piece () const noexcept -> PieceType
constexpr auto promoted_type () const noexcept -> MaybePieceType
constexpr auto to () const noexcept -> Square

(Note that these are not member symbols.)

constexpr auto operator<=> (const Move &first, const Move &second) noexcept -> std::strong_ordering
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

Detailed Description

This struct encodes information about a move.

Moves are encoded as a starting and ending square, as well as a piece type.

Castling is considered a king move.

En passant cannot be identified solely using the information in this struct; based on the starting and ending squares of the capturing pawn, an en passant capture appears just like any other pawn capture.

This struct also does not directly identify if the move is a capture.

Null moves are supported; a null move essentially indicates swapping the side to move and incrementing the halfmove counter without changing any piece positions.

Todo
Flags for en passant, maybe isCapture/isCheck, isCastling

Definition at line 75 of file Move.hpp.

Constructor & Destructor Documentation

◆ Move() [1/2]

chess::moves::Move::Move ( )
constexprdefault

Creates a null move.

◆ Move() [2/2]

chess::moves::Move::Move ( Square start,
Square end,
PieceType type,
MaybePieceType promotedType = std::nullopt )
constexpr

Creates a move.

Definition at line 225 of file Move.hpp.

Member Function Documentation

◆ from()

auto chess::moves::Move::from ( ) const -> Square
nodiscardconstexprnoexcept

Returns the starting square of the moving piece. In the case of en passant, this is the square that the capturing pawn started on. In the case of castling, this is the square that the king started on.

Definition at line 247 of file Move.hpp.

◆ hash()

auto chess::moves::Move::hash ( ) const -> size_t
nodiscardconstexprnoexcept

Returns a hash code for this move.

Definition at line 298 of file Move.hpp.

◆ is_castling()

auto chess::moves::Move::is_castling ( ) const -> bool
nodiscardconstexprnoexcept

Returns true if this move is castling (in either direction).

Definition at line 290 of file Move.hpp.

◆ is_null()

auto chess::moves::Move::is_null ( ) const -> bool
inlinenodiscardnoexcept

Returns true if this is a null move.

Definition at line 109 of file Move.hpp.

◆ is_promotion()

auto chess::moves::Move::is_promotion ( ) const -> bool
nodiscardconstexprnoexcept

Returns true if this move is a promotion.

Definition at line 277 of file Move.hpp.

◆ is_under_promotion()

auto chess::moves::Move::is_under_promotion ( ) const -> bool
nodiscardconstexprnoexcept

Returns true if this move is a promotion to a piece other than a queen.

Definition at line 283 of file Move.hpp.

◆ operator==()

auto chess::moves::Move::operator== ( const Move & ) const -> bool=default
constexprdefaultnoexcept

◆ piece()

auto chess::moves::Move::piece ( ) const -> PieceType
nodiscardconstexprnoexcept

Returns the type of the moving piece. For a promotion, this is pawn; for castling, this is king.

Definition at line 257 of file Move.hpp.

◆ promoted_type()

auto chess::moves::Move::promoted_type ( ) const -> MaybePieceType
nodiscardconstexprnoexcept

Returns the promoted-to type, or nullopt if this move is not a promotion.

Definition at line 267 of file Move.hpp.

◆ to()

auto chess::moves::Move::to ( ) const -> Square
nodiscardconstexprnoexcept

Returns the ending square of the moving piece. In the case of en passant, this is the square that the capturing pawn lands on. In the case of castling, this is the square that the king ends on.

Definition at line 252 of file Move.hpp.


The documentation for this struct was generated from the following file:
  • libchess/include/libchess/moves/Move.hpp