|
HooverChessUtils_PgnReader 0.9.0
|
Miscellaneous string utilities. More...
#include <pgnreader-string-utils.h>
Static Public Member Functions | |
| static constexpr char | colChar (Square sq) noexcept |
| Returns a file (column) designation character for a square, lower-case. | |
| static constexpr char | rowChar (Square sq) noexcept |
| Returns a rank (row) designation character for a square, lower-case. | |
| static MiniString< 2U > | sourceMaskToString (SquareSet srcMask) noexcept |
| Source mask to SAN notation. | |
| static MiniString< 13U > | plyNumToString (std::uint32_t plyNum) noexcept |
Ply number to move string (e.g., "5." or "11...") | |
| template<std::size_t bufSize, typename UintRangeType , typename UintType > | |
| static char * | genUnsignedToString (char *s, UintType num) noexcept |
| Generic unsigned integer to string converter. | |
| static MiniString< 13U > | moveNumToString (std::uint_fast32_t moveNum, Color turn) noexcept |
Move number and side-to-move to move string (e.g., "5." or "11...") | |
| static constexpr char | promoPieceChar (Piece promo) noexcept |
| Translates promotion piece to character (N/B/R/Q). Return value is unspecified for any other piece values. | |
| static constexpr MiniString< 1U > | pieceToSanStr (Piece p) noexcept |
| Translates piece to SAN string. | |
| static MiniString< 7U > | moveToSanAndPlay (ChessBoard &board, Move move) |
| Generates minimal SAN for a move and plays it. The move is fully validated by this function. | |
| static MiniString< 7U > | moveToSan (const ChessBoard &board, Move move) |
| Generates minimal SAN for a move. The move is fully validated by this function. | |
| static std::string_view | pieceAndColorToString (PieceAndColor pc) noexcept |
Returns a name string for PieceAndColor. | |
| static std::string_view | squareToString (Square sq, std::string_view emptySquareName) noexcept |
Returns a name string for Square. | |
| static std::string_view | moveTypeAndPromotionToString (MoveTypeAndPromotion typeAndPromotion) noexcept |
| Move type and promotion code to string. | |
| static void | boardToFEN (const ChessBoard &board, FenString &fen) noexcept |
Builds a FEN string for the position on board. | |
Miscellaneous string utilities.
|
staticnoexcept |
Builds a FEN string for the position on board.
| [in] | board | Board that holds the position |
| [in] | fen | FEN for the position |
|
inlinestaticconstexprnoexcept |
Returns a file (column) designation character for a square, lower-case.
| [in] | sq | Valid square |
'a'–'h')
|
inlinestaticnoexcept |
Generic unsigned integer to string converter.
| bufSize | Reserved buffer size. Must be exactly the maximum string size for the integer type |
| UintType | Unsigned integer type |
| [out] | s | Pointer to receive the string |
| [in] | num | Number to convert |
s is the length of the written string.
|
inlinestaticnoexcept |
Move number and side-to-move to move string (e.g., "5." or "11...")
| [in] | moveNum | Move number |
| [in] | turn | Side to move |
"1." for first white move and "2..." for second black move.
|
inlinestatic |
Generates minimal SAN for a move. The move is fully validated by this function.
| [in] | board | Chess board |
| [in] | move | Move to play |
| PgnError(PgnErrorCode::ILLEGAL_MOVE) | Illegal move |
This function is implemented using moveToSanAndPlay(). In case the intention is to produce SAN notation while replaying the moves, it is faster to invoke moveToSanAndPlay() to combine the activities than calling this function and ChessBoard::doMove() separately.
moveToSanAndPlay() for full specification.
|
static |
Generates minimal SAN for a move and plays it. The move is fully validated by this function.
| [in] | board | Chess board |
| [in] | move | Move to play |
| PgnError(PgnErrorCode::ILLEGAL_MOVE) | Illegal move. board is not modified. |
| std::logic_error | Bad move type board is not modified. |
Format of the produced move string is as follows:
SAN_MOVE = move_body ('+' | '#')?
where move_body consists the piece identifier and source/destination identifiers, appended with check/checkmate indicators as necessary.
move_body has the following format:
Type (MoveTypeAndPromotion) | Condition (first match) | Format | Example |
|---|---|---|---|
MoveTypeAndPromotion::REGULAR_PAWN_MOVE | No capture | <dest_file> <dest_rank> | e4 |
MoveTypeAndPromotion::REGULAR_PAWN_MOVE | Capture | <src_file> 'x' <dest_file> <dest_rank> | exc6cxd6 |
MoveTypeAndPromotion::EN_PASSANT | None | <src_file> 'x' <dest_file> <dest_rank> | exc5cxd6 |
MoveTypeAndPromotion::REGULAR_KNIGHT_MOVEMoveTypeAndPromotion::REGULAR_BISHOP_MOVEMoveTypeAndPromotion::REGULAR_ROOK_MOVEMoveTypeAndPromotion::REGULAR_QUEEN_MOVE | No disambiguation required | <piece> <dest_file> <dest_rank> | Ne4 |
<piece> <dest_file> 'x' <dest_rank> | Nxf6 | ||
| Source file disambiguation required | <piece> <src_file> <dest_file> <dest_rank> | Nbd2 | |
<piece> <src_file> 'x' <dest_file> <dest_rank> | Nexg5 | ||
| Source rank disambiguation required | <piece> <src_rank> <dest_file> <dest_rank> | R1h3 | |
<piece> <src_rank> 'x' <dest_file> <dest_rank> | N5xd4 | ||
| Source square required | <piece> <src_file> <src_rank> <dest_file> <dest_rank> | Qd4d5 | |
<piece> <src_file> 'x' <src_rank> <dest_file> <dest_rank> | Qc2xc5 | ||
MoveTypeAndPromotion::REGULAR_KING_MOVE | No capture | 'K' <dest_file> <dest_rank> | Kd2 |
| Capture | "Kx" <dest_file> <dest_rank> | Kxf7 | |
MoveTypeAndPromotion::CASTLING_SHORT | None | "O-O" | O-O |
MoveTypeAndPromotion::CASTLING_LONG | None | "O-O-O" | O-O-O |
MoveTypeAndPromotion::PROMO_KNIGHTMoveTypeAndPromotion::PROMO_BISHOPMoveTypeAndPromotion::PROMO_ROOKMoveTypeAndPromotion::PROMO_QUEEN | No capture | <dest_file> <dest_rank> '=' <piece> | a8=Q |
| Capture | <src_file> 'x' <dest_file> <dest_rank> '=' <piece> | fxg1=N |
Disambiguation requirements:
| Disambiguation requirement | Description |
|---|---|
| None | There is only a single legal move for the piece and destination. |
| Source file | Two or more legal moves match with the piece and destination square. Specifying source file makes the move unambiguous. |
| Source rank | Two or more legal moves match with the piece and destination square. Specifying source rank makes the move unambiguous. |
| Source square | More than one legal move matches with the piece and destination square. Neither source file nor source rank is sufficient to make the move unambiguous. |
Note that the potential check/checkmate indicator is not used for disambiguation.
"Na1xb3+"
|
staticnoexcept |
Move type and promotion code to string.
| [in] | typeAndPromotion | Move type and promotion piece |
"??"
|
staticnoexcept |
Returns a name string for PieceAndColor.
| [in] | pc | PieceAndColor. May be valid or invalid |
For all concrete PieceAndColor values, the name is a two-letter color (lower-case 'w' or 'b') and piece (upper-case 'P', 'N', 'B', 'R', 'Q', 'K') string. For none values, the return string is two spaces. For any other values, the returned string is "??".
|
inlinestaticconstexprnoexcept |
Translates piece to SAN string.
| [in] | p | Piece |
| Piece | Returned string |
|---|---|
Piece::PAWN | Empty string |
Piece::KNIGHT | "N" |
Piece::BISHOP | "B" |
Piece::ROOK | "R" |
Piece::QUEEN | "Q" |
Piece::KING | "K" |
| Other | "?" |
|
inlinestaticnoexcept |
Ply number to move string (e.g., "5." or "11...")
| [in] | plyNum | Ply number |
"1." for first white move and "2..." for second black move.
|
inlinestaticconstexprnoexcept |
Translates promotion piece to character (N/B/R/Q). Return value is unspecified for any other piece values.
| [in] | promo | Promotion piece |
|
inlinestaticconstexprnoexcept |
Returns a rank (row) designation character for a square, lower-case.
| [in] | sq | Valid square |
'1'–'8')
|
staticnoexcept |
Source mask to SAN notation.
| [in] | srcMask | Source mask derived from SAN notation |
| Source mask | Returned string |
|---|---|
SquareSet::all() | Empty string (no source mask was specified) |
SquareSet::column(N) | File designation character (source column was specified) |
SquareSet::row(N) | Rank designation character (source row was specified) |
SquareSet::square(sq) | File and rank designation characters (both source column and row were specified) |
| Other | Unspecified but not undefined behavior |
|
staticnoexcept |
Returns a name string for Square.
| [in] | sq | Square. May be valid or invalid |
| [in] | emptySquareName | Name for Square::NONE and invalid squares. |
For all valid squares, the name is a two-letter file and rank. For example: "a1", "h8".