libscid 0.1.0
Chess applications made easy.
Loading...
Searching...
No Matches
game_info.h
1#pragma once
2
3#include "scid/core/date.h"
4#include "scid/core/game_result.h"
5#include "scid/core/rating.h"
6#include "scid/database/common.h"
7#include "scid/database/game_id.h"
8#include "scid/database/matsig.h"
9#include <array>
10#include <cstdint>
11#include <optional>
12
13namespace scid::database {
14
15inline constexpr std::uint32_t GAME_FLAG_MASK_ALL = 0xffffffff;
16
17enum gameFlagT : std::uint32_t {
18 GAME_FLAG_START = 0,
19 GAME_FLAG_PROMO,
20 GAME_FLAG_UPROMO,
21 GAME_FLAG_DELETE,
22 GAME_FLAG_WHITE_OP,
23 GAME_FLAG_BLACK_OP,
24 GAME_FLAG_MIDDLEGAME,
25 GAME_FLAG_ENDGAME,
26 GAME_FLAG_NOVELTY,
27 GAME_FLAG_PAWN,
28 GAME_FLAG_TACTICS,
29 GAME_FLAG_KSIDE,
30 GAME_FLAG_QSIDE,
31 GAME_FLAG_BRILLIANCY,
32 GAME_FLAG_BLUNDER,
33 GAME_FLAG_USER,
34 GAME_FLAG_CUSTOM1,
35 GAME_FLAG_CUSTOM2,
36 GAME_FLAG_CUSTOM3,
37 GAME_FLAG_CUSTOM4,
38 GAME_FLAG_CUSTOM5,
39 GAME_FLAG_CUSTOM6,
40 GAME_FLAG_COUNT,
41};
42
43std::uint32_t gameFlagMaskFromChar(char flag);
44scid::core::uint gameFlagIndexFromChar(char flag);
45std::uint32_t gameFlagMaskFromString(const char* flags);
46
47struct GameInfo {
48 std::uint64_t offset = 0;
49 std::uint32_t length = 0;
50 idNumberT white = 0;
51 idNumberT black = 0;
52 idNumberT event = 0;
53 idNumberT site = 0;
54 idNumberT round = 0;
55 scid::core::ratingT whiteElo = 0;
56 scid::core::ratingT blackElo = 0;
57 scid::core::ratingTypeT whiteRatingType = 0;
58 scid::core::ratingTypeT blackRatingType = 0;
59 scid::core::dateT date = scid::core::ZERO_DATE;
60 scid::core::dateT eventDate = scid::core::ZERO_DATE;
61 scid::core::resultT result = scid::core::RESULT_None;
62 scid::core::uint variationCount = 0;
63 scid::core::uint commentCount = 0;
64 scid::core::uint nagCount = 0;
65 std::uint16_t halfMoveCount = 0;
66 matSigT finalMaterial = 0;
67 scid::core::byte storedLineCode = 0;
68 EcoCode ecoCode = ECO_CODE_NONE;
69 std::uint32_t flags = 0;
70 std::array<scid::core::byte, 9> homePawnData = {};
71 bool chessStd = true;
72
73 bool hasFlag(std::uint32_t mask) const { return (flags & mask) == mask; }
74 bool hasStartFlag() const { return hasFlag(1u << GAME_FLAG_START); }
75 bool hasPromotionsFlag() const { return hasFlag(1u << GAME_FLAG_PROMO); }
76 bool hasUnderPromoFlag() const { return hasFlag(1u << GAME_FLAG_UPROMO); }
77 bool hasDeleteFlag() const { return hasFlag(1u << GAME_FLAG_DELETE); }
78 bool hasComments() const { return commentCount > 0; }
79 bool hasVariations() const { return variationCount > 0; }
80 scid::core::uint year() const { return scid::core::date_GetYear(date); }
81 scid::core::uint month() const { return scid::core::date_GetMonth(date); }
82 scid::core::uint day() const { return scid::core::date_GetDay(date); }
83 scid::core::byte rating() const;
84 scid::core::uint flagString(char* dest, const char* flags) const;
85};
86
88 std::optional<scid::core::dateT> date;
89 std::optional<idNumberT> event;
90 std::optional<idNumberT> round;
91 std::optional<scid::core::ratingT> whiteElo;
92 std::optional<scid::core::ratingT> blackElo;
93 std::optional<EcoCode> ecoCode;
94
95 bool empty() const {
96 return !date && !event && !round && !whiteElo && !blackElo &&
97 !ecoCode;
98 }
99};
100
101} // namespace scid::database
class StrRange - parse a string interpreting its content as 1 or 2 integers separated by whitespace.
Definition common.h:30
Definition game_info.h:87
Definition game_info.h:47