libscid snapshot+1833ab5ad39d
Chess applications made easy.
Source on GitHub License GPL v2
Loading...
Searching...
No Matches
scid::core Namespace Reference

Chess games, positions, movetext and notation. More...

Namespaces

namespace  gamepos
 Named board positions commonly used as game starting points.
 
namespace  move_predicates
 Stateless helpers used by Position move validation.
 
namespace  pgn
 PGN import, export and movetext traversal helpers.
 

Classes

class  DString
 Legacy growable string builder. More...
 
struct  EventInfo
 Event-level metadata for a game. More...
 
class  FullMove
 Compact value type for encoded moves. More...
 
class  Game
 A mutable chess game made of header metadata, an optional start position, and a recursive movetext tree. More...
 
class  GameCursor
 A read-only cursor over a game's mainline and recursive variations. More...
 
struct  GameHeader
 The structured header of a chess game. More...
 
class  HashVal
 Zobrist hash table for piece/square occupancy. More...
 
struct  Move
 A played move in a mainline or variation. More...
 
struct  MoveAction
 Position-resolved, reversible move action. More...
 
class  MoveList
 Fixed-capacity container for generated moves. More...
 
struct  MoveMetadata
 Annotation metadata attached to a move. More...
 
struct  MoveSequence
 An ordered sequence of moves. More...
 
struct  MoveSpec
 Describes a requested move before it is resolved against a position. More...
 
struct  Movetext
 The playable move tree of a game. More...
 
class  MovetextCursor
 A mutable cursor over a game's mainline and recursive variations. More...
 
class  MovetextLocation
 A restorable cursor position inside a game's movetext tree. More...
 
class  PieceFromByte
 Compile-time byte-to-piece lookup for FEN and legacy board strings. More...
 
struct  Player
 A chess player as recorded in a game header. More...
 
class  Position
 Complete chess position with move generation, validation, and notation. More...
 
struct  Rating
 A player's rating and the rating system it belongs to. More...
 
struct  ScoredMove
 MoveAction plus an ordering score used by search and move pickers. More...
 
class  SquareList
 Fixed-capacity list of squares. More...
 
class  SquareSet
 64-bit set of on-board squares. More...
 
struct  Variation
 A recursive annotation variation. More...
 

Typedefs

typedef uint32_t dateT
 Packed date value used by games, indexes, and statistics.
 
typedef unsigned short errorT
 Status code returned by legacy Scid APIs.
 
using TagPair = std::pair< std::string, std::string >
 A PGN tag pair that is not represented by one of the typed header fields.
 
typedef byte resultT
 Game result code used by Game and database statistics.
 
using sanStringT = char[SAN_STRING_SIZE]
 Legacy fixed-size SAN buffer type.
 
using sanFlagT = byte
 Controls whether generated SAN includes check and mate suffix testing.
 
typedef uint genMovesT
 Move-generation filter flags.
 
typedef unsigned char byte
 8-bit unsigned scalar used by legacy file formats and board tables.
 
typedef std::uint16_t ushort
 16-bit unsigned scalar used by counters and compact encodings.
 
typedef std::uint32_t uint
 32-bit unsigned scalar used by hashes, sizes, and database fields.
 
typedef std::int32_t sint
 32-bit signed scalar used by scores and signed counters.
 
typedef byte pieceT
 Piece code.
 
typedef byte colorT
 Colour code: WHITE, BLACK, or NOCOLOR.
 
typedef byte squareT
 Square code: A1..H8, COLOR_SQUARE, or NULL_SQUARE.
 
typedef byte rankT
 Rank code: RANK_1..RANK_8 or NO_RANK.
 
typedef byte fyleT
 File code.
 
typedef byte directionT
 Direction code used as an index into movement tables.
 
typedef byte leftDiagT
 A1-H8 diagonal index.
 
typedef byte rightDiagT
 H1-A8 diagonal index.
 
typedef byte castleDirT
 Castling side code: QSIDE or KSIDE.
 
using ratingT = ushort
 Numeric player rating value.
 
using ratingTypeT = byte
 Identifier for the rating system stored with a player rating.
 

Enumerations

enum class  Nag : std::uint8_t {
  None = 0 , GoodMove = 1 , PoorMove = 2 , ExcellentMove = 3 ,
  Blunder = 4 , InterestingMove = 5 , DubiousMove = 6 , OnlyMove = 8 ,
  Equal = 10 , Unclear = 13 , WhiteSlight = 14 , BlackSlight = 15 ,
  WhiteClear = 16 , BlackClear = 17 , WhiteDecisive = 18 , BlackDecisive = 19 ,
  WhiteCrushing = 20 , BlackCrushing = 21 , ZugZwang = 22 , BlackZugZwang = 23 ,
  MoreRoom = 26 , DevelopmentAdvantage = 35 , WithInitiative = 36 , WithAttack = 40 ,
  WithBlackAttack = 41 , Compensation = 44 , SlightCentre = 48 , Centre = 50 ,
  SlightKingSide = 54 , ModerateKingSide = 56 , KingSide = 58 , SlightQueenSide = 60 ,
  ModerateQueenSide = 62 , QueenSide = 64 , SlightCounterPlay = 130 , BlackSlightCounterPlay = 131 ,
  CounterPlay = 132 , BlackCounterPlay = 133 , DecisiveCounterPlay = 134 , BlackDecisiveCounterPlay = 135 ,
  TimeLimit = 136 , WithIdea = 140 , BetterIs = 142 , VariousMoves = 144 ,
  Comment = 145 , Novelty = 146 , WeakPoint = 147 , Ending = 148 ,
  File = 149 , Diagonal = 150 , BishopPair = 151 , OppositeBishops = 153 ,
  SameBishops = 154 , Etc = 190 , DoublePawns = 191 , SeparatedPawns = 192 ,
  UnitedPawns = 193 , Diagram = 201 , See = 210 , Mate = 211 ,
  PassedPawn = 212 , MorePawns = 213 , With = 214 , Without = 215
}
 Numeric annotation glyph values used in PGN movetext. More...
 

Functions

bool piece_IsKing (pieceT p)
 Returns true when p has king as its uncoloured type.
 
bool piece_IsSlider (pieceT p)
 Returns true when p is a queen, rook, or bishop type.
 
pieceT piece_FromChar (int x)
 Converts a SAN piece designator to an uncoloured piece type.
 
leftDiagT square_LeftDiag (squareT sq)
 Returns the A1-H8 diagonal index for sq.
 
rightDiagT square_RightDiag (squareT sq)
 Returns the H1-A8 diagonal index for sq.
 
colorT square_Color (squareT sq)
 Returns WHITE for a light square and BLACK for a dark square.
 
squareT square_FlipFyle (squareT sq)
 Returns sq with its file mirrored, for example A1 becomes H1.
 
squareT square_FlipRank (squareT sq)
 Returns sq with its rank mirrored, for example A1 becomes A8.
 
squareT square_FlipDiag (squareT sq)
 Returns sq reflected across the A1-H8 diagonal.
 
uint square_Distance (squareT from, squareT to)
 Returns the distance in king moves between two on-board squares.
 
squareT square_NearestCorner (squareT sq)
 Returns the nearest corner square, choosing the lower-file/lower-rank corner on ties.
 
bool square_IsCornerSquare (squareT sq)
 Returns true when sq is A1, H1, A8, or H8.
 
bool square_IsEdgeSquare (squareT sq)
 Returns true when sq is on the board edge.
 
int square_EdgeDistance (squareT sq)
 Returns the distance from sq to the nearest board edge.
 
bool square_IsKnightHop (squareT from, squareT to)
 Returns true when from and to form a knight move.
 
char square_FyleChar (squareT sq)
 Returns the file character for sq.
 
char square_RankChar (squareT sq)
 Returns the rank character for sq.
 
directionT direction_Opposite (directionT d)
 Returns the opposite direction for d.
 
bool direction_IsDiagonal (directionT dir)
 Returns true when dir is one of the four diagonal directions.
 
int direction_Delta (directionT dir)
 Returns the board-array delta for dir.
 
bool square_Adjacent (squareT from, squareT to)
 Returns true when two squares are king-adjacent, including equality.
 
uint32_t date_GetYear (dateT date)
 Returns the year field, or 0 when unknown.
 
uint32_t date_GetMonth (dateT date)
 Returns the month field, or 0 when unknown.
 
uint32_t date_GetDay (dateT date)
 Returns the day field, or 0 when unknown.
 
bool date_isPartial (dateT date)
 Returns true when the year, month, or day field is unknown.
 
void date_DecodeToString (dateT date, char *str)
 Writes a PGN date tag value into str.
 
dateT date_EncodeFromString (const char *str)
 Parses a dotted date string into dateT.
 
dateT date_parsePGNTag (const char *str, size_t len)
 Parses a PGN Date tag value.
 
dateT date_parsePGNTag (std::pair< const char *, const char * > str)
 Parses a PGN Date tag value described by a pointer pair.
 
constexpr std::uint8_t nagCode (Nag nag)
 Returns the PGN numeric code for nag.
 
constexpr Nag nagFromCode (std::uint8_t value)
 Builds a Nag value from a numeric PGN code.
 
std::string nagToString (Nag nag, bool asSymbol)
 Formats nag as a symbolic annotation when possible, or $n.
 
std::string_view nagToSymbol (Nag nag)
 Returns the symbolic form for nag, or an empty view if none is known.
 
Nag nagFromString (std::string_view text)
 Parses symbolic, bare numeric, or $n NAG text.
 
colorT color_Flip (colorT c)
 Returns the opposite real colour.
 
char color_Char (colorT c)
 Returns the legacy printable colour character for c.
 
colorT piece_Color (pieceT p)
 Returns the colour of a coloured piece, or NOCOLOR for EMPTY.
 
colorT piece_Color_NotEmpty (pieceT p)
 Faster colour extraction when p is known not to be EMPTY.
 
pieceT piece_Type (pieceT p)
 Returns the uncoloured piece type encoded in p.
 
pieceT piece_Make (colorT c, pieceT p)
 Builds a coloured piece code from a real colour and an uncoloured type.
 
char piece_Char (pieceT p)
 Returns the piece-type character for p.
 
rankT rank_FromChar (char c)
 Converts '1'..'8' to a rank, or NO_RANK for invalid input.
 
fyleT fyle_FromChar (char c)
 Converts 'a'..'h' to a file, or NO_FYLE for invalid input.
 
constexpr squareT square_Make (fyleT f, rankT r)
 Builds a square from file and rank codes.
 
constexpr fyleT square_Fyle (squareT sq)
 Returns the file of sq.
 
constexpr rankT square_Rank (squareT sq)
 Returns the rank of sq.
 
constexpr squareT square_Relative (colorT c, squareT sq)
 Returns sq from White's perspective for WHITE, Black's for BLACK.
 
constexpr rankT rank_Relative (colorT c, rankT r)
 Returns r from White's perspective for WHITE, Black's for BLACK.
 
constexpr squareT square_Move (squareT sq, directionT dir)
 Returns the one-step destination from sq in dir, or NS off-board.
 
constexpr squareT square_Last (squareT sq, directionT dir)
 Returns the last on-board square on the ray from sq in dir.
 

Variables

const squareT knightAttacks [66][9]
 Knight attack targets for each square, terminated by NULL_SQUARE.
 
const squareT kingAttacks [66][9]
 King attack targets for each square, excluding castling, terminated by NULL_SQUARE.
 
const pieceT WM = 16
 White minor-piece aggregate marker used by material-only searches.
 
const pieceT BM = 17
 Black minor-piece aggregate marker used by material-only searches.
 
const uint MAX_PIECE_TYPES = 18
 Number of piece-like codes covered by board lookup tables.
 
const pieceT PIECE_FLIP [MAX_PIECE_TYPES]
 Maps each piece code to the same piece with colour reversed.
 
const bool PIECE_IS_SLIDER [8]
 True for uncoloured piece types that slide along rays.
 
const uint rankFyleDist [64]
 Chebyshev distance lookup by rank or file.
 
const int edgeDist [66]
 Distance of each square from the closest edge, with -1 for sentinels.
 
const directionT NULL_DIR = 0
 No direction or no aligned ray.
 
const directionT UP = 1
 One rank toward Black's home rank.
 
const directionT DOWN = 2
 One rank toward White's home rank.
 
const directionT LEFT = 4
 One file toward A-file.
 
const directionT RIGHT = 8
 One file toward H-file.
 
const directionT UP_LEFT = (UP | LEFT)
 Diagonal toward A8.
 
const directionT UP_RIGHT = (UP | RIGHT)
 Diagonal toward H8.
 
const directionT DOWN_LEFT = (DOWN | LEFT)
 Diagonal toward A1.
 
const directionT DOWN_RIGHT = (DOWN | RIGHT)
 Diagonal toward H1.
 
const directionT dirOpposite [11]
 Direction-opposite lookup table indexed by directionT values.
 
const bool dirIsDiagonal [11]
 Diagonal-direction lookup table indexed by directionT values.
 
const int dirDelta [11]
 Board-array delta for a one-square step in each direction.
 
const pieceT START_BOARD [66]
 Standard starting board, including COLOR_SQUARE and NULL_SQUARE sentinels.
 
const colorT BOARD_SQUARECOLOR [66]
 Standard board square colours, with NOCOLOR for sentinels.
 
const dateT ZERO_DATE = 0
 Unknown date.
 
const uint32_t YEAR_SHIFT = 9
 Bit shift of the year field.
 
const uint32_t MONTH_SHIFT = 5
 Bit shift of the month field.
 
const uint32_t DAY_SHIFT = 0
 Bit shift of the day field.
 
const uint32_t YEAR_MAX = 2047
 Maximum representable year.
 
const errorT OK = 0
 Shared status and error-code values.
 
const errorT ERROR = 1
 Unclassified failure.
 
const errorT ERROR_UserCancel = 2
 Operation was cancelled by the user or progress callback.
 
const errorT ERROR_BadArg = 3
 Invalid argument or unsupported argument combination.
 
const errorT ERROR_FileOpen = 101
 File could not be opened.
 
const errorT ERROR_FileWrite = 102
 File write failed.
 
const errorT ERROR_FileRead = 103
 File read failed.
 
const errorT ERROR_FileSeek = 104
 File seek failed.
 
const errorT ERROR_BadMagic = 105
 File signature or magic bytes did not match the expected format.
 
const errorT ERROR_FileNotOpen = 106
 Operation requires an open file but none is open.
 
const errorT ERROR_FileInUse = 107
 File is already in use.
 
const errorT ERROR_FileMode = 108
 File was opened in a mode incompatible with the requested operation.
 
const errorT ERROR_FileVersion = 109
 File format version is not supported by this code.
 
const errorT ERROR_OldScidVersion = 110
 File requires an older Scid compatibility path.
 
const errorT ERROR_FileReadOnly = 111
 Operation would modify a read-only file.
 
const errorT ERROR_CompactRemove = 121
 Compaction failed while removing or replacing old database files.
 
const errorT ERROR_MallocFailed = 151
 Memory allocation failed.
 
const errorT ERROR_CorruptData = 152
 Data is structurally corrupt or cannot be trusted.
 
const errorT ERROR_Corrupt = 152
 Alias for ERROR_CorruptData.
 
const errorT ERROR_Full = 201
 Container or database has reached capacity.
 
const errorT ERROR_NameNotFound = 202
 Requested name entry was not found.
 
const errorT ERROR_NotFound = 202
 Alias for ERROR_NameNotFound.
 
const errorT ERROR_NameExists = 203
 Requested name entry already exists.
 
const errorT ERROR_Exists = 203
 Alias for ERROR_NameExists.
 
const errorT ERROR_NameBaseEmpty = 204
 Name table is empty.
 
const errorT ERROR_Empty = 204
 Alias for ERROR_NameBaseEmpty.
 
const errorT ERROR_NoMatchFound = 205
 Search or lookup completed without a match.
 
const errorT ERROR_NameDataLoss = 206
 Some name data was lost or could not be recovered while loading.
 
const errorT ERROR_NameTooLong = 207
 Name exceeds the format limit.
 
const errorT ERROR_NameLimit = 208
 Name table has reached its entry limit.
 
const errorT ERROR_OffsetLimit = 209
 Encoded offset exceeds the format limit.
 
const errorT ERROR_GameLengthLimit = 210
 Encoded game data exceeds the format limit.
 
const errorT ERROR_NumGamesLimit = 211
 Database has reached its game-count limit.
 
const errorT ERROR_InvalidFEN = 301
 FEN text could not be parsed as a valid position.
 
const errorT ERROR_InvalidMove = 302
 Move text could not be parsed or applied legally.
 
const errorT ERROR_PieceCount = 303
 Position has an invalid piece count or material arrangement.
 
const errorT ERROR_Game = 400
 Generic game or movetext failure.
 
const errorT ERROR_EndOfMoveList = 401
 Cursor or decoder reached the end of a move list.
 
const errorT ERROR_StartOfMoveList = 402
 Cursor is already at the start of a move list.
 
const errorT ERROR_NoVariation = 403
 Requested variation does not exist.
 
const errorT ERROR_EmptyVariation = 404
 Requested variation exists but contains no moves.
 
const errorT ERROR_VariationLimit = 405
 Variation nesting or count limit was exceeded.
 
const errorT ERROR_Decode = 406
 Encoded game or tag data could not be decoded.
 
const errorT ERROR_GameFull = 407
 Game movetext has reached its storage limit.
 
const errorT ERROR_BufferFull = 601
 Output buffer has no space for the requested write.
 
const errorT ERROR_BufferRead = 602
 Input buffer did not contain enough data for the requested read.
 
const errorT ERROR_CodecUnsupFeat = 701
 Codec does not support the requested feature.
 
const errorT ERROR_CodecChess960 = 702
 Codec cannot represent a Chess960-specific feature.
 
const uint NUM_RESULT_TYPES = 4
 Number of result codes, including unknown/unfinished games.
 
const resultT RESULT_None = 0
 Unknown, unfinished, or no-result game.
 
const resultT RESULT_White = 1
 White win.
 
const resultT RESULT_Black = 2
 Black win.
 
const resultT RESULT_Draw = 3
 Draw.
 
const uint RESULT_SCORE [4] = {1, 2, 0, 1}
 Half-point scores from White's perspective: win=2, draw=1, loss=0.
 
const char RESULT_CHAR [4] = {'*', '1', '0', '='}
 Compact one-character result markers.
 
const char RESULT_STR [4][4] = {"*", "1-0", "0-1", "=-="}
 Short result strings used by legacy displays.
 
const char RESULT_LONGSTR [4][8] = {"*", "1-0", "0-1", "1/2-1/2"}
 PGN result strings.
 
const resultT RESULT_OPPOSITE [4]
 Result from the opposite player's perspective.
 
constexpr auto HASH = HashVal()
 Shared Zobrist helper used to add piece/square contributions.
 
auto const & UNHASH = HASH
 Alias for HASH used when removing piece/square contributions.
 
constexpr unsigned stdStartPawnHash
 Pawn hash of the standard chess starting position.
 
constexpr unsigned stdStartHash
 Full-piece hash of the standard chess starting position.
 
const uint MAX_LEGAL_MOVES = 256
 Maximum number of legal moves held by a MoveList.
 
constexpr std::uint8_t maxNagCode = nagCode(Nag::Without)
 Largest named Nag code currently recognised by libscid.
 
constexpr std::size_t SAN_STRING_SIZE = 10
 Maximum storage size for legacy fixed-size SAN buffers.
 
constexpr sanFlagT SAN_NO_CHECKTEST = 0
 Generate SAN without checking for check or mate suffixes.
 
constexpr sanFlagT SAN_CHECKTEST = 1
 Generate SAN with check suffix testing.
 
constexpr sanFlagT SAN_MATETEST = 2
 Generate SAN with mate suffix testing.
 
constexpr std::size_t UCI_MOVE_STRING_SIZE = 6
 Maximum storage size for legacy fixed-size UCI move buffers.
 
const byte WQ_CASTLE = 1
 Castling-right bit for White queenside castling.
 
const byte WK_CASTLE = 2
 Castling-right bit for White kingside castling.
 
const byte BQ_CASTLE = 4
 Castling-right bit for Black queenside castling.
 
const byte BK_CASTLE = 8
 Castling-right bit for Black kingside castling.
 
const genMovesT GEN_CAPTURES = 1
 Generate capturing moves only.
 
const genMovesT GEN_NON_CAPS = 2
 Generate non-capturing moves only.
 
const genMovesT GEN_ALL_MOVES = (GEN_CAPTURES | GEN_NON_CAPS)
 Generate all legal moves.
 
const castleDirT QSIDE = 0
 Queenside castling direction.
 
const castleDirT KSIDE = 1
 Kingside castling direction.
 
const unsigned NUM_COLOR_TYPES = 2
 Number of real chess colours.
 
const colorT WHITE = 0
 White side.
 
const colorT BLACK = 1
 Black side.
 
const colorT NOCOLOR = 2
 Sentinel colour for empty or non-board values.
 
const char COLOR_CHAR [3] = {'W', 'B', '_'}
 Printable colour letters used by legacy board strings.
 
const pieceT INVALID_PIECE = 0
 Invalid or absent piece type.
 
const pieceT KING = 1
 Uncoloured king type.
 
const pieceT QUEEN = 2
 Uncoloured queen type.
 
const pieceT ROOK = 3
 Uncoloured rook type.
 
const pieceT BISHOP = 4
 Uncoloured bishop type.
 
const pieceT KNIGHT = 5
 Uncoloured knight type.
 
const pieceT PAWN = 6
 Uncoloured pawn type.
 
const pieceT EMPTY = 7
 Empty board square marker.
 
const pieceT END_OF_BOARD = 0
 Zero terminator for legacy board strings.
 
const pieceT WK = 1
 White king.
 
const pieceT WQ = 2
 White queen.
 
const pieceT WR = 3
 White rook.
 
const pieceT WB = 4
 White bishop.
 
const pieceT WN = 5
 White knight.
 
const pieceT WP = 6
 White pawn.
 
const pieceT BK = 9
 Black king.
 
const pieceT BQ = 10
 Black queen.
 
const pieceT BR = 11
 Black rook.
 
const pieceT BB = 12
 Black bishop.
 
const pieceT BN = 13
 Black knight.
 
const pieceT BP = 14
 Black pawn.
 
const char PIECE_CHAR [] = "xKQRBNP.xkqrbnpxMm"
 Piece-code to character table.
 
constexpr auto pieceFromByte = PieceFromByte()
 Global byte-to-piece lookup table.
 
const squareT A1 = 0
 Board squares in rank-major order, followed by sentinel squares.
 
const squareT B1 = 1
 
const squareT C1 = 2
 
const squareT D1 = 3
 
const squareT E1 = 4
 
const squareT F1 = 5
 
const squareT G1 = 6
 
const squareT H1 = 7
 
const squareT A2 = 8
 
const squareT B2 = 9
 
const squareT C2 = 10
 
const squareT D2 = 11
 
const squareT E2 = 12
 
const squareT F2 = 13
 
const squareT G2 = 14
 
const squareT H2 = 15
 
const squareT A3 = 16
 
const squareT B3 = 17
 
const squareT C3 = 18
 
const squareT D3 = 19
 
const squareT E3 = 20
 
const squareT F3 = 21
 
const squareT G3 = 22
 
const squareT H3 = 23
 
const squareT A4 = 24
 
const squareT B4 = 25
 
const squareT C4 = 26
 
const squareT D4 = 27
 
const squareT E4 = 28
 
const squareT F4 = 29
 
const squareT G4 = 30
 
const squareT H4 = 31
 
const squareT A5 = 32
 
const squareT B5 = 33
 
const squareT C5 = 34
 
const squareT D5 = 35
 
const squareT E5 = 36
 
const squareT F5 = 37
 
const squareT G5 = 38
 
const squareT H5 = 39
 
const squareT A6 = 40
 
const squareT B6 = 41
 
const squareT C6 = 42
 
const squareT D6 = 43
 
const squareT E6 = 44
 
const squareT F6 = 45
 
const squareT G6 = 46
 
const squareT H6 = 47
 
const squareT A7 = 48
 
const squareT B7 = 49
 
const squareT C7 = 50
 
const squareT D7 = 51
 
const squareT E7 = 52
 
const squareT F7 = 53
 
const squareT G7 = 54
 
const squareT H7 = 55
 
const squareT A8 = 56
 
const squareT B8 = 57
 
const squareT C8 = 58
 
const squareT D8 = 59
 
const squareT E8 = 60
 
const squareT F8 = 61
 
const squareT G8 = 62
 
const squareT H8 = 63
 
const squareT COLOR_SQUARE = 64
 
const squareT NULL_SQUARE = 65
 
const squareT NS = 65
 
const rankT RANK_1 = 0
 Rank constants and invalid rank sentinel.
 
const rankT RANK_2 = 1
 
const rankT RANK_3 = 2
 
const rankT RANK_4 = 3
 
const rankT RANK_5 = 4
 
const rankT RANK_6 = 5
 
const rankT RANK_7 = 6
 
const rankT RANK_8 = 7
 
const rankT NO_RANK = 64
 
const fyleT A_FYLE = 0
 File constants and invalid file sentinel.
 
const fyleT B_FYLE = 1
 
const fyleT C_FYLE = 2
 
const fyleT D_FYLE = 3
 
const fyleT E_FYLE = 4
 
const fyleT F_FYLE = 5
 
const fyleT G_FYLE = 6
 
const fyleT H_FYLE = 7
 
const fyleT NO_FYLE = 64
 
constexpr ratingTypeT RATING_Elo = 0
 FIDE Elo rating.
 
constexpr ratingTypeT RATING_Rating = 1
 Generic rating tag when the original rating system is not more specific.
 
constexpr ratingTypeT RATING_Rapid = 2
 Rapid rating.
 
constexpr ratingTypeT RATING_ICCF = 3
 International Correspondence Chess Federation rating.
 
constexpr ratingTypeT RATING_USCF = 4
 United States Chess Federation rating.
 
constexpr ratingTypeT RATING_DWZ = 5
 Deutsche Wertungszahl rating.
 
constexpr ratingTypeT RATING_BCF = 6
 British/English Chess Federation rating.
 
constexpr std::size_t NUM_RATING_TYPES = 7
 Number of defined rating-system identifiers.
 
constexpr const char * ratingTypeNames [NUM_RATING_TYPES+1]
 Null-terminated table of PGN-facing rating-system names.
 
constexpr uint MAX_SQUARELIST = 65
 Maximum SquareList capacity: 64 board squares plus NULL_SQUARE.
 
constexpr squareT precomputed_sqMove [66][11]
 One-step movement lookup indexed by square and direction.
 
constexpr squareT precomputed_sqLast [66][11]
 Ray-end lookup indexed by square and direction.
 

Detailed Description

Chess games, positions, movetext and notation.

Core is the chess model of libscid. It owns the in-memory representation of a game, the board state needed to validate and replay moves, and the value types that keep chess data portable across storage, PGN, notation and user-facing tools.

Most work in this namespace revolves around two aggregates: scid::core::Game owns complete editable game records, while scid::core::Position owns a board state at one moment in a game. The movetext, cursor, notation and PGN APIs sit around those aggregates as tree, traversal and text-mapping layers.

Typedef Documentation

◆ errorT

typedef unsigned short scid::core::errorT

Status code returned by legacy Scid APIs.

OK is zero and all error values are non-zero, so an errorT can be used in simple boolean checks when only success/failure matters.

◆ fyleT

File code.

Named "fyle" to avoid confusion with disk files.

◆ pieceT

Piece code.

Values may be piece types, coloured pieces, EMPTY, or sentinels.

◆ ratingT

using scid::core::ratingT = typedef ushort

Numeric player rating value.

A value of 0 is commonly used by callers to represent an unknown rating. Database codecs may impose tighter storage limits than the full range of the underlying type.

Enumeration Type Documentation

◆ Nag

enum class scid::core::Nag : std::uint8_t
strong

Numeric annotation glyph values used in PGN movetext.

The enum names cover the annotation values recognised by libscid. Values map directly to PGN $n NAG codes and may also have a symbolic representation such as !, ??, or D.

Function Documentation

◆ color_Flip()

colorT scid::core::color_Flip ( colorT  c)
inline

Returns the opposite real colour.

c must be WHITE or BLACK.

◆ date_DecodeToString()

void scid::core::date_DecodeToString ( dateT  date,
char *  str 
)
inline

Writes a PGN date tag value into str.

Unknown fields are written as question marks, for example ????.??.?? or 2024.??.??. The destination must have room for at least eleven bytes including the terminator.

◆ date_EncodeFromString()

dateT scid::core::date_EncodeFromString ( const char *  str)
inline

Parses a dotted date string into dateT.

This legacy parser accepts numeric fields in yyyy.mm.dd order. Out of range fields stop further precision from being added: an invalid month keeps the parsed year, and an invalid day keeps the parsed year and month.

◆ date_parsePGNTag()

dateT scid::core::date_parsePGNTag ( const char *  str,
size_t  len 
)
inline

Parses a PGN Date tag value.

Full YYYY.MM.DD values are accepted, as are partial values with unknown month/day fields. The parser also accepts compact month/day forms such as YYYY.M.D. Invalid or out-of-range fields are treated as unknown.

Parameters
strmemory containing the tag value.
lennumber of bytes in str.
Returns
the parsed date, or ZERO_DATE when the year is missing or invalid.

◆ nagFromString()

Nag scid::core::nagFromString ( std::string_view  text)

Parses symbolic, bare numeric, or $n NAG text.

Unknown, malformed, or out-of-range text returns Nag::None.

◆ nagToString()

std::string scid::core::nagToString ( Nag  nag,
bool  asSymbol 
)

Formats nag as a symbolic annotation when possible, or $n.

Nag::None formats as an empty string. When asSymbol is true but no symbol is known for the code, numeric $n form is used.

◆ piece_FromChar()

pieceT scid::core::piece_FromChar ( int  x)
inline

Converts a SAN piece designator to an uncoloured piece type.

Pawns have no SAN designator here, so 'P' and unknown characters return EMPTY.

◆ square_Last()

constexpr squareT scid::core::square_Last ( squareT  sq,
directionT  dir 
)
constexpr

Returns the last on-board square on the ray from sq in dir.

For on-board squares and valid directions the result is always on-board. When the ray immediately leaves the board, sq is returned.

Variable Documentation

◆ BOARD_SQUARECOLOR

const colorT scid::core::BOARD_SQUARECOLOR[66]
Initial value:
= {
}
const colorT BLACK
Black side.
Definition primitives.h:74
const colorT WHITE
White side.
Definition primitives.h:72
const colorT NOCOLOR
Sentinel colour for empty or non-board values.
Definition primitives.h:76

Standard board square colours, with NOCOLOR for sentinels.

◆ dirDelta

const int scid::core::dirDelta[11]
Initial value:
= {
0,
8,
-8,
0,
-1,
7,
-9,
0,
1,
9,
-7
}

Board-array delta for a one-square step in each direction.

◆ dirIsDiagonal

const bool scid::core::dirIsDiagonal[11]
Initial value:
= {
false,
false,
false,
false,
false,
true,
true,
false,
false,
true,
true
}

Diagonal-direction lookup table indexed by directionT values.

◆ dirOpposite

const directionT scid::core::dirOpposite[11]
Initial value:
= {
DOWN,
UP,
LEFT,
}
const directionT UP
One rank toward Black's home rank.
Definition board.h:174
const directionT LEFT
One file toward A-file.
Definition board.h:178
const directionT DOWN
One rank toward White's home rank.
Definition board.h:176
const directionT UP_RIGHT
Diagonal toward H8.
Definition board.h:184
const directionT DOWN_RIGHT
Diagonal toward H1.
Definition board.h:188
const directionT NULL_DIR
No direction or no aligned ray.
Definition board.h:172
const directionT RIGHT
One file toward H-file.
Definition board.h:180
const directionT UP_LEFT
Diagonal toward A8.
Definition board.h:182
const directionT DOWN_LEFT
Diagonal toward A1.
Definition board.h:186

Direction-opposite lookup table indexed by directionT values.

◆ edgeDist

const int scid::core::edgeDist[66]
Initial value:
= {
0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0,
0, 1, 2, 2, 2, 2, 1, 0,
0, 1, 2, 3, 3, 2, 1, 0,
0, 1, 2, 3, 3, 2, 1, 0,
0, 1, 2, 2, 2, 2, 1, 0,
0, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0,
-1, -1
}

Distance of each square from the closest edge, with -1 for sentinels.

◆ OK

const errorT scid::core::OK = 0

Shared status and error-code values.

The numeric ranges are conventional: low values are general errors, 100s are file I/O, 200s are database/name errors, 300s are position errors, 400s are game/movetext errors, 600s are buffer errors, and 700s are codec feature errors. Success.

◆ PIECE_FLIP

const pieceT scid::core::PIECE_FLIP[MAX_PIECE_TYPES]
Initial value:
= {
BK, BQ, BR, BB, BN, BP,
WK, WQ, WR, WB, WN, WP,
}
const pieceT BK
Black king.
Definition primitives.h:124
const pieceT WN
White knight.
Definition primitives.h:120
const pieceT BN
Black knight.
Definition primitives.h:132
const pieceT WK
White king.
Definition primitives.h:112
const pieceT BQ
Black queen.
Definition primitives.h:126
const pieceT END_OF_BOARD
Zero terminator for legacy board strings.
Definition primitives.h:110
const pieceT BM
Black minor-piece aggregate marker used by material-only searches.
Definition board.h:16
const pieceT BP
Black pawn.
Definition primitives.h:134
const pieceT BB
Black bishop.
Definition primitives.h:130
const pieceT WR
White rook.
Definition primitives.h:116
const pieceT WB
White bishop.
Definition primitives.h:118
const pieceT WM
White minor-piece aggregate marker used by material-only searches.
Definition board.h:14
const pieceT WP
White pawn.
Definition primitives.h:122
const pieceT EMPTY
Empty board square marker.
Definition primitives.h:108
const pieceT BR
Black rook.
Definition primitives.h:128
const pieceT WQ
White queen.
Definition primitives.h:114

Maps each piece code to the same piece with colour reversed.

◆ PIECE_IS_SLIDER

const bool scid::core::PIECE_IS_SLIDER[8]
Initial value:
= {
false,
false, true, true, true, false, false,
false,
}

True for uncoloured piece types that slide along rays.

◆ precomputed_sqLast

constexpr squareT scid::core::precomputed_sqLast[66][11]
inlineconstexpr

Ray-end lookup indexed by square and direction.

For on-board squares and valid directions, the result is the last on-board square reachable by continuing in that direction. If movement in that direction is immediately off-board, the original square is returned. Sentinel squares map to NS.

◆ precomputed_sqMove

constexpr squareT scid::core::precomputed_sqMove[66][11]
inlineconstexpr

One-step movement lookup indexed by square and direction.

Off-board moves, COLOR_SQUARE, and NULL_SQUARE map to NS.

◆ rankFyleDist

const uint scid::core::rankFyleDist[64]
Initial value:
= {
0, 1, 2, 3, 4, 5, 6, 7,
1, 0, 1, 2, 3, 4, 5, 6,
2, 1, 0, 1, 2, 3, 4, 5,
3, 2, 1, 0, 1, 2, 3, 4,
4, 3, 2, 1, 0, 1, 2, 3,
5, 4, 3, 2, 1, 0, 1, 2,
6, 5, 4, 3, 2, 1, 0, 1,
7, 6, 5, 4, 3, 2, 1, 0
}

Chebyshev distance lookup by rank or file.

◆ RATING_BCF

constexpr ratingTypeT scid::core::RATING_BCF = 6
inlineconstexpr

British/English Chess Federation rating.

The legacy constant name is kept for compatibility; the public display name in ratingTypeNames is "ECF".

◆ ratingTypeNames

constexpr const char* scid::core::ratingTypeNames[NUM_RATING_TYPES+1]
inlineconstexpr
Initial value:
= {
"Elo", "Rating", "Rapid", "ICCF", "USCF", "DWZ", "ECF", nullptr}

Null-terminated table of PGN-facing rating-system names.

The table is indexed by a ratingTypeT value and has a trailing nullptr sentinel for legacy loops.

◆ RESULT_OPPOSITE

const resultT scid::core::RESULT_OPPOSITE[4]
Initial value:
= {
const resultT RESULT_Draw
Draw.
Definition game_result.h:22
const resultT RESULT_None
Unknown, unfinished, or no-result game.
Definition game_result.h:16
const resultT RESULT_Black
Black win.
Definition game_result.h:20
const resultT RESULT_White
White win.
Definition game_result.h:18

Result from the opposite player's perspective.

◆ START_BOARD

const pieceT scid::core::START_BOARD[66]
Initial value:

Standard starting board, including COLOR_SQUARE and NULL_SQUARE sentinels.

◆ stdStartHash

constexpr unsigned scid::core::stdStartHash
inlineconstexpr
Initial value:
= [] {
auto h = stdStartPawnHash;
HASH (h,WR,A1); HASH (h,WN,B1); HASH (h,WB,C1); HASH (h,WQ,D1);
HASH (h,WK,E1); HASH (h,WB,F1); HASH (h,WN,G1); HASH (h,WR,H1);
HASH (h,BR,A8); HASH (h,BN,B8); HASH (h,BB,C8); HASH (h,BQ,D8);
HASH (h,BK,E8); HASH (h,BB,F8); HASH (h,BN,G8); HASH (h,BR,H8);
return h;
}()
constexpr unsigned stdStartPawnHash
Pawn hash of the standard chess starting position.
Definition hash.h:202
constexpr auto HASH
Shared Zobrist helper used to add piece/square contributions.
Definition hash.h:192

Full-piece hash of the standard chess starting position.

◆ stdStartPawnHash

constexpr unsigned scid::core::stdStartPawnHash
inlineconstexpr
Initial value:
= [] {
unsigned h = 0;
HASH (h,WP,A2); HASH (h,WP,B2); HASH (h,WP,C2); HASH (h,WP,D2);
HASH (h,WP,E2); HASH (h,WP,F2); HASH (h,WP,G2); HASH (h,WP,H2);
HASH (h,BP,A7); HASH (h,BP,B7); HASH (h,BP,C7); HASH (h,BP,D7);
HASH (h,BP,E7); HASH (h,BP,F7); HASH (h,BP,G7); HASH (h,BP,H7);
return h;
}()

Pawn hash of the standard chess starting position.

◆ UNHASH

auto const& scid::core::UNHASH = HASH
inline

Alias for HASH used when removing piece/square contributions.

Zobrist removal is also an XOR operation, so hashing and unhashing share the same implementation.