|
BenBot 1.7.5
A chess engine
|
#include <libchess/game/Position.hpp>
Public Types | |
| using | Hash = std::uint64_t |
Public Member Functions | |
| Position () | |
| void | flip () |
| auto | free () const noexcept -> Bitboard |
| template<Color Side> | |
| auto | get_backward_pawns () const noexcept -> Bitboard |
| template<Color Side> | |
| auto | get_passed_pawns () const noexcept -> Bitboard |
| auto | is_black_to_move () const noexcept -> bool |
| auto | is_capture (Move move) const noexcept -> bool |
| auto | is_check () const noexcept -> bool |
| auto | is_en_passant (Move move) const noexcept -> bool |
| auto | is_illegal () const -> std::optional< std::string > |
| auto | is_legal (Move move) const -> bool |
| auto | is_quiet (Move move) const noexcept -> bool |
| auto | is_white_to_move () const noexcept -> bool |
| void | make_move (Move move) |
| void | make_null_move () |
| auto | occupied () const noexcept -> Bitboard |
| auto | operator== (const Position &other) const noexcept -> bool |
| void | refresh_zobrist () |
Piece access | |
| template<Color Side> | |
| auto | pieces_for () noexcept -> Pieces & |
| template<Color Side> | |
| auto | pieces_for () const noexcept -> const Pieces & |
| template<Color Side> | |
| auto | castling_rights_for () const noexcept -> CastlingRights |
| auto | our_pieces () noexcept -> Pieces & |
| auto | our_pieces () const noexcept -> const Pieces & |
| auto | their_pieces () noexcept -> Pieces & |
| auto | their_pieces () const noexcept -> const Pieces & |
File queries | |
| auto | is_file_open (File file) const noexcept -> bool |
| auto | get_open_files () const noexcept |
| auto | is_file_half_open (File file) const noexcept -> bool |
| auto | get_half_open_files () const noexcept |
Game result queries | |
| auto | is_checkmate () const -> bool |
| auto | is_stalemate () const -> bool |
| auto | is_fifty_move_draw () const -> bool |
| auto | is_threefold_repetition () const noexcept -> bool |
| auto | is_draw_by_insufficient_material () const noexcept -> bool |
| auto | is_draw () const -> bool |
| auto | get_result () const -> std::optional< Result > |
Static Public Member Functions | |
| static auto | empty () -> Position |
Public Attributes | |
| CastlingRights | blackCastlingRights |
| Pieces | blackPieces { Color::Black } |
| std::optional< Square > | enPassantTargetSquare |
| std::uint_least64_t | fullMoveCounter { UINT64_C(1) } |
| std::uint_least8_t | halfmoveClock { UINT8_C(0) } |
| Hash | hash { UINT64_C(0) } |
| Color | sideToMove { Color::White } |
| CastlingRights | whiteCastlingRights |
| Pieces | whitePieces { Color::White } |
Related Symbols | |
(Note that these are not member symbols.) | |
| auto | after_move (const Position &starting, Move move) -> Position |
| auto | after_null_move (const Position &starting) -> Position |
| auto | flipped (const Position &starting) -> Position |
| auto | print_ascii (const Position &position) -> std::string |
| auto | print_utf8 (const Position &position) -> std::string |
This class models an instant in a game of chess.
It describes where all the pieces are placed, as well as some additional metadata such as castling rights, side to move, en passant possibility, etc.
Definition at line 74 of file Position.hpp.
| using chess::game::Position::Hash = std::uint64_t |
Unsigned 64-bit integer used for hash values.
Definition at line 130 of file Position.hpp.
Creates a Position object representing the starting position.
|
inlinenodiscardnoexcept |
Returns the castling rights for the given color.
Definition at line 170 of file Position.hpp.
|
inlinestaticnodiscard |
Returns an empty position with none of the piece bitboards initialized. This is useful for tasks like parsing a FEN string, for example. After you've set up the position, don't forget to call whitePieces.refresh_occupied(), blackPieces.refresh_occupied(), and refresh_zobrist() to update all relevant cached state.
Definition at line 427 of file Position.hpp.
| void chess::game::Position::flip | ( | ) |
Performs a color flip of this position.
|
inlinenodiscardnoexcept |
Returns a bitboard that is the inverse of the occupied() board.
Definition at line 234 of file Position.hpp.
|
nodiscardnoexcept |
Returns a bitboard containing the locations of backward pawns for the given side.
Definition at line 522 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns an iterable range of File enumeration values corresponding to all half-open files in this position.
Definition at line 501 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns an iterable range of File enumeration values corresponding to all open files in this position.
Definition at line 486 of file Position.hpp.
|
nodiscardnoexcept |
Returns a bitboard containing the locations of passed pawns for the given side.
Definition at line 508 of file Position.hpp.
|
nodiscard |
If this position is a conclusive draw or checkmate, returns the appropriate Result enumeration. Returns nullopt if this position is not a conclusive one.
|
inlinenodiscardnoexcept |
Returns true if the side to move is Black.
Definition at line 223 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns true if the given move is a capture, including en passant.
Definition at line 471 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns true if the king of the side to move is in check.
Definition at line 266 of file Position.hpp.
|
nodiscard |
Returns true if the king is attacked and the side to move has no legal moves.
|
nodiscard |
Returns true if the game has concluded in a draw.
|
nodiscardnoexcept |
Returns true if this position is either lone kings or lone king vs. king and bishop or knight.
|
inlinenodiscardnoexcept |
Returns true if the given move is an en passant capture in the current position.
Definition at line 464 of file Position.hpp.
|
nodiscard |
Returns true if this position is a fifty-move draw, based on the halfmoveClock. Note that in order for the game to be drawn, the side to move must have at least 1 legal move.
|
inlinenodiscardnoexcept |
Returns true if only one side has a pawn on the given file.
Definition at line 492 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns true if there are no pawns of either color on the given file.
Definition at line 481 of file Position.hpp.
|
nodiscard |
Tests if the position is legal. If it is, returns nullopt; if the position is illegal, returns an explanatory string describing the error condition detecting. This function conducts basic checks about the number of each type of piece, but this is not an exhaustive validation that a position can definitively be reached from the starting position.
|
inlinenodiscard |
Returns true if the given move is legal (that is, the king is not left in check). This function does not verify piece movement mechanics or that a piece of the given type exists on the starting square; this function only verifies that making the move does not leave the side's king in check.
Definition at line 455 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns true if the given move is quiet - ie, does not alter material.
Definition at line 476 of file Position.hpp.
|
nodiscard |
Returns true if the side to move has no legal moves, but their king is not attacked.
|
inlinenodiscardnoexcept |
Returns true if this position is a draw by threefold repetition.
Definition at line 439 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns true if the side to move is White.
Definition at line 217 of file Position.hpp.
| void chess::game::Position::make_move | ( | Move | move | ) |
Makes a move to alter the position.
Makes a null move. This essentially represents the side to move "passing" their turn. This does update the Zobrist hash, halfmove clock and fullmove counter in the same way that make_move() does.
|
inlinenodiscardnoexcept |
Returns a bitboard that is the union of all White and Black piece positions.
Definition at line 231 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns true if the two positions have the same Zobrist hash.
Definition at line 140 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns the pieces belonging to the side to move.
Definition at line 188 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns the pieces belonging to the side to move.
Definition at line 179 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns the piece set representing the given color.
Definition at line 160 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns the piece set representing the given color.
Definition at line 150 of file Position.hpp.
Recalculates the Zobrist hash for this position.
|
inlinenodiscardnoexcept |
Returns the pieces belonging to the side-to-move's opponent.
Definition at line 206 of file Position.hpp.
|
inlinenodiscardnoexcept |
Returns the pieces belonging to the side-to-move's opponent.
Definition at line 197 of file Position.hpp.
| CastlingRights chess::game::Position::blackCastlingRights |
Castling rights for the Black player.
Definition at line 101 of file Position.hpp.
| Pieces chess::game::Position::blackPieces { Color::Black } |
The positions of the Black pieces.
Definition at line 92 of file Position.hpp.
| std::optional<Square> chess::game::Position::enPassantTargetSquare |
If the last move was a pawn double-push, then this holds the square that a pawn would land on after capturing en passant. This is always set to a non-null value if the last move was a pawn double-push, even if no enemy pawns are actually in position to perform the capture.
Definition at line 109 of file Position.hpp.
| std::uint_least64_t chess::game::Position::fullMoveCounter { UINT64_C(1) } |
The number of full moves in the game. This value is monotonically increasing throughout the game, and is incremented after every Black move.
Definition at line 127 of file Position.hpp.
| std::uint_least8_t chess::game::Position::halfmoveClock { UINT8_C(0) } |
This is a ply counter that enforces the 50-move rule. The counter is incremented after every move and reset by captures and pawn moves; if the counter reaches 100 and the side to move has at least 1 legal move, then the game is drawn.
Definition at line 121 of file Position.hpp.
| Hash chess::game::Position::hash { UINT64_C(0) } |
The Zobrist hash value of this position. This value is incrementally updated by the make_move() function. If you manually change attributes of the position, call the refresh_zobrist() function to recalculate it.
Definition at line 137 of file Position.hpp.
| Color chess::game::Position::sideToMove { Color::White } |
Indicates whose move it is in this position.
Definition at line 95 of file Position.hpp.
| CastlingRights chess::game::Position::whiteCastlingRights |
Castling rights for the White player.
Definition at line 98 of file Position.hpp.
| Pieces chess::game::Position::whitePieces { Color::White } |
The positions of the White pieces.
Definition at line 84 of file Position.hpp.