HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions
PGN-reader implementation

Classes

struct  hoover_chess_utils::pgn_reader::MoveGenFunctions
 Move generator functions. More...
 
class  hoover_chess_utils::pgn_reader::Attacks_AArch64_SVE2_BitPerm
 Slider attacks implementation using PEXT/PDEP. More...
 
class  hoover_chess_utils::pgn_reader::Attacks_BlackMagic
 Slider attacks implementation using Elementary Bitboards. More...
 
class  hoover_chess_utils::pgn_reader::Attacks_Elementary_Bitboards
 Slider attacks implementation using Elementary Bitboards. More...
 
class  hoover_chess_utils::pgn_reader::Attacks_Portable
 Portable implementations for attacks. More...
 
class  hoover_chess_utils::pgn_reader::Attacks_BMI2
 Slider attacks implementation using PEXT/PDEP. More...
 
class  hoover_chess_utils::pgn_reader::Attacks
 Piece attack tables. More...
 
class  hoover_chess_utils::pgn_reader::Intercepts
 Check interceptions and pin checks. More...
 
struct  hoover_chess_utils::pgn_reader::BitTricks
 Collection of bit tricks for 64-bit words. More...
 
class  hoover_chess_utils::pgn_reader::PgnParser_NullActions
 PGN parser null semantic actions. This is useful only for testing and documentation purposes. More...
 
class  hoover_chess_utils::pgn_reader::PgnParser< T_ActionHandler >
 The PGN parser. More...
 
class  hoover_chess_utils::pgn_reader::PgnScanner
 The PGN scanner (lexer) More...
 
struct  hoover_chess_utils::pgn_reader::PgnScannerTokenInfo_PAWN_MOVE
 Additional token info for pawn move. More...
 
struct  hoover_chess_utils::pgn_reader::PgnScannerTokenInfo_PIECE_MOVE
 Additional token info for piece move. More...
 
struct  hoover_chess_utils::pgn_reader::PgnScannerTokenInfo_MOVENUM
 Additional token info for move number token. More...
 
struct  hoover_chess_utils::pgn_reader::PgnScannerTokenInfo_NAG
 Additional token info for numeric annotation glyph. More...
 
struct  hoover_chess_utils::pgn_reader::PgnScannerTokenInfo_RESULT
 Additional token info for game result. More...
 
struct  hoover_chess_utils::pgn_reader::PgnScannerTokenInfo_ERROR
 Additional token info for error token. More...
 
union  hoover_chess_utils::pgn_reader::PgnScannerTokenInfo
 Union of all additional scanner information. The applicable union member depends the PGN scanner token (see PgnScannerToken). More...
 

Macros

#define SQUARESET_ENUMERATE_INTERNAL(sq, squareSet, tmpMask, ...)
 Implementation of SQUARESET_ENUMERATE().
 

Enumerations

enum class  hoover_chess_utils::pgn_reader::MoveGenType { hoover_chess_utils::pgn_reader::MoveGenType::NO_CHECK = 0U , hoover_chess_utils::pgn_reader::MoveGenType::CHECK , hoover_chess_utils::pgn_reader::MoveGenType::DOUBLE_CHECK }
 Move generator type. More...
 
enum  hoover_chess_utils::pgn_reader::PgnScannerToken : std::uint8_t {
  hoover_chess_utils::pgn_reader::NONE = 0U , hoover_chess_utils::pgn_reader::END_OF_FILE , hoover_chess_utils::pgn_reader::TAG_START , hoover_chess_utils::pgn_reader::TAG_KEY ,
  hoover_chess_utils::pgn_reader::TAG_VALUE , hoover_chess_utils::pgn_reader::TAG_END , hoover_chess_utils::pgn_reader::VARIATION_START , hoover_chess_utils::pgn_reader::VARIATION_END ,
  hoover_chess_utils::pgn_reader::MOVENUM , hoover_chess_utils::pgn_reader::MOVE_PAWN , hoover_chess_utils::pgn_reader::MOVE_PAWN_CAPTURE , hoover_chess_utils::pgn_reader::MOVE_PAWN_PROMO ,
  hoover_chess_utils::pgn_reader::MOVE_PAWN_PROMO_CAPTURE , hoover_chess_utils::pgn_reader::MOVE_PIECE_KNIGHT , hoover_chess_utils::pgn_reader::MOVE_PIECE_BISHOP , hoover_chess_utils::pgn_reader::MOVE_PIECE_ROOK ,
  hoover_chess_utils::pgn_reader::MOVE_PIECE_QUEEN , hoover_chess_utils::pgn_reader::MOVE_PIECE_KING , hoover_chess_utils::pgn_reader::MOVE_SHORT_CASTLE , hoover_chess_utils::pgn_reader::MOVE_LONG_CASTLE ,
  hoover_chess_utils::pgn_reader::NAG , hoover_chess_utils::pgn_reader::COMMENT_START , hoover_chess_utils::pgn_reader::COMMENT_TEXT , hoover_chess_utils::pgn_reader::COMMENT_NEWLINE ,
  hoover_chess_utils::pgn_reader::COMMENT_END , hoover_chess_utils::pgn_reader::RESULT , hoover_chess_utils::pgn_reader::ERROR
}
 PGN scanner token. More...
 

Functions

template<typename U64Type >
const U64Type & hoover_chess_utils::pgn_reader::turnSpecificLookup (const std::array< U64Type, 2U > &array, Color turn) noexcept
 Piece attack tables.
 
template<typename U64Type , std::size_t N>
const U64Type & hoover_chess_utils::pgn_reader::turnSpecificArrayLookup (const std::array< std::array< U64Type, 2U >, N > &array, std::size_t i, Color turn) noexcept
 Optimized lookup for arrays indexed by general index and turn (side-to-move).
 
constexpr std::uint32_t hoover_chess_utils::pgn_reader::pgnScannerTokenToMaskBit (PgnScannerToken token) noexcept
 

Detailed Description

Macro Definition Documentation

◆ SQUARESET_ENUMERATE_INTERNAL

#define SQUARESET_ENUMERATE_INTERNAL (   sq,
  squareSet,
  tmpMask,
  ... 
)
Value:
do \
{ \
SquareSet tmpMask { squareSet }; \
\
while (true) \
{ \
const Square sq { tmpMask.firstSquare() }; \
\
if (sq > Square::H8) \
break; \
\
tmpMask &= ~SquareSet::square(sq); \
\
__VA_ARGS__; \
} \
} \
while (false)

Implementation of SQUARESET_ENUMERATE().

Parameters
[in]sqVariable name for enumerated squares
[in]squareSetSquare set
[in]tmpMaskVariable name for temporary square set
[in]...Statements to execute per enumerated square. Statements may include continue and break. The last statement does not have to end with semi-colon.
Remarks
Macro approach is used here for the following reasons:
  • Lambdas are not quite optimal:
    • CLANG has difficulties in optimizing lambda expressions to be as efficient as expanded macros.
    • We can't exit the enumeration loop by a returning from a lambda
  • A regular iterator holding a square set mask is not as efficient. The problem is that begin() != end() condition means comparing masks. However, it's faster to do sq > Square::H8 comparison after determining the lowest populated bit before calculating the mask after the lowest bit has been extracted.

Enumeration Type Documentation

◆ MoveGenType

Move generator type.

Enumerator
NO_CHECK 

Move generator for when the king is not in check. All moves are considered.

CHECK 

Move generator for when the king is in check (single). King moves are considered first, castling moves are not considered at all, and regular piece moves must either capture the checker or intercept the check.

DOUBLE_CHECK 

Move generator for when the king is in double check. Only king moves are considered.

◆ PgnScannerToken

PGN scanner token.

See also
PgnScanner::nextToken()
Enumerator
NONE 

Null token (placeholder only)

END_OF_FILE 

End of file.

TAG_START 

PGN tag start ('[')

TAG_KEY 

PGN tag key.

TAG_VALUE 

PGN tag value.

TAG_END 

PGN tag end (']')

VARIATION_START 

Variation start ('(')

VARIATION_END 

Variation end ('(')

MOVENUM 

Move number.

@sa <tt>@ref PgnScannerTokenInfo_MOVENUM</tt> 
MOVE_PAWN 

Pawn advance (non-promoting)

@sa <tt>@ref PgnScannerTokenInfo_PAWN_MOVE</tt> 
MOVE_PAWN_CAPTURE 

Pawn capture (non-promoting)

@sa <tt>@ref PgnScannerTokenInfo_PAWN_MOVE</tt> 
MOVE_PAWN_PROMO 

Pawn capture (promoting)

@sa <tt>@ref PgnScannerTokenInfo_PAWN_MOVE</tt> 
MOVE_PAWN_PROMO_CAPTURE 

Pawn capture (promoting)

@sa <tt>@ref PgnScannerTokenInfo_PAWN_MOVE</tt> 
MOVE_PIECE_KNIGHT 

Knight move.

@sa <tt>@ref PgnScannerTokenInfo_PIECE_MOVE</tt> 
MOVE_PIECE_BISHOP 

Bishop move.

@sa <tt>@ref PgnScannerTokenInfo_PIECE_MOVE</tt> 
MOVE_PIECE_ROOK 

Rook move.

@sa <tt>@ref PgnScannerTokenInfo_PIECE_MOVE</tt> 
MOVE_PIECE_QUEEN 

Queen move.

@sa <tt>@ref PgnScannerTokenInfo_PIECE_MOVE</tt> 
MOVE_PIECE_KING 

King move.

@sa <tt>@ref PgnScannerTokenInfo_PIECE_MOVE</tt> 
MOVE_SHORT_CASTLE 

Short castling move.

MOVE_LONG_CASTLE 

Long castling move.

NAG 

Numeric annotation glyph.

@sa <tt>@ref PgnScannerTokenInfo_NAG</tt> 
COMMENT_START 

Block comment start.

COMMENT_TEXT 

Block comment text line OR single line comment.

COMMENT_NEWLINE 

New line within a block comment.

COMMENT_END 

Block comment end.

RESULT 

PGN game result (terminator)

@sa <tt>@ref PgnScannerTokenInfo_RESULT</tt> 
ERROR 

Tokenizer error.

The error token spans at least a single character. Hence, error recovery may be attempted by reading
error tokens until a regular tokens is encountered.

@sa <tt>@ref PgnScannerTokenInfo_ERROR</tt> 

Function Documentation

◆ pgnScannerTokenToMaskBit()

constexpr std::uint32_t hoover_chess_utils::pgn_reader::pgnScannerTokenToMaskBit ( PgnScannerToken  token)
inlineconstexprnoexcept

◆ turnSpecificArrayLookup()

template<typename U64Type , std::size_t N>
const U64Type & hoover_chess_utils::pgn_reader::turnSpecificArrayLookup ( const std::array< std::array< U64Type, 2U >, N > &  array,
std::size_t  i,
Color  turn 
)
inlinenoexcept

Optimized lookup for arrays indexed by general index and turn (side-to-move).

Template Parameters
U64Type64-bit type, generally intended to be SquareSet or std::uint64_t
NArray length in pairs of U64Type
Parameters
[in]arrayArray of U64Type element pairs
[in]iArray index
[in]turnSide to move. Must be either Color::WHITE or Color::BLACK (asserted)
Returns
Const reference to the element

The implementation makes a strong assumption that turn is one of { Color::WHITE, Color::BLACK }. This can eliminate otherwise superfluous arithmetic operations when computing the memory address. In particular, turn can be used as is as the array byte offset, instead of resetting the lowest 3 bits (i.e., byte_offset = (turn / 8) * 8).

◆ turnSpecificLookup()

template<typename U64Type >
const U64Type & hoover_chess_utils::pgn_reader::turnSpecificLookup ( const std::array< U64Type, 2U > &  array,
Color  turn 
)
inlinenoexcept

Piece attack tables.

Optimized lookup for arrays indexed by turn (side-to-move).

Template Parameters
U64Type64-bit type, generally intended to be SquareSet or std::uint64_t
Parameters
[in]arrayArray of U64Type elements, size 2 (element for Color::WHITE and Color::BLACK)
[in]turnSide to move. Must be either Color::WHITE or Color::BLACK (asserted)
Returns
Const reference to the element

The expected array layout is

Index Content
0 Element for Color::WHITE
1 Element for Color::BLACK

The implementation makes a strong assumption that turn is one of { Color::WHITE, Color::BLACK }. This can eliminate otherwise superfluous arithmetic operations when computing the memory address. In particular, turn can be used as is as the array byte offset, instead of resetting the lowest 3 bits (i.e., byte_offset = (turn / 8) * 8).