BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
PGN.hpp
Go to the documentation of this file.
1/*
2 * ======================================================================================
3 *
4 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░
5 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
6 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
7 * ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
8 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
9 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
10 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
11 *
12 * ======================================================================================
13 */
14
19
20#pragma once
21
22#include <cstdint> // IWYU pragma: keep - for std::uint_least8_t
23#include <expected>
27#include <optional>
28#include <string>
29#include <string_view>
30#include <unordered_map>
31#include <vector>
32
33namespace chess::notation {
34
35using game::Position;
36using std::string;
37
66
72struct [[nodiscard]] GameRecord final {
77 std::unordered_map<string, string> metadata;
78
81
90 std::optional<game::Result> result;
91
93 struct Move final {
96
100 string comment;
101
111 std::vector<NAG> nags;
112
114 using Variation = std::vector<Move>;
115
120 std::vector<Variation> variations;
121 };
122
124 std::vector<Move> moves;
125
127 [[nodiscard]] auto get_final_position() const -> Position;
128};
129
138[[nodiscard]] auto from_pgn(std::string_view pgnText)
139 -> std::expected<GameRecord, std::string_view>;
140
151[[nodiscard]] auto parse_all_pgns(std::string_view fileContent)
152 -> std::vector<GameRecord>;
153
165[[nodiscard]] auto to_pgn(const GameRecord& game, bool useBlockComments = true) -> string;
166
167} // namespace chess::notation
auto parse_all_pgns(std::string_view fileContent) -> std::vector< GameRecord >
auto to_pgn(const GameRecord &game, bool useBlockComments=true) -> string
auto from_pgn(std::string_view pgnText) -> std::expected< GameRecord, std::string_view >
@ BlackInitiative
Indicates that black has the initiative in this position.
Definition PGN.hpp:64
@ WhiteSlightAdvantage
Indicates that white has a slight advantage in this position.
Definition PGN.hpp:54
@ Good
A good move, typically displayed as !.
Definition PGN.hpp:45
@ WhiteDecisiveAdvantage
Indicates that white has a decisive advantage in this position.
Definition PGN.hpp:56
@ Brilliant
A brilliant move, typically displayed as !!.
Definition PGN.hpp:46
@ Interesting
A speculative or interesting move, typically displayed as !?.
Definition PGN.hpp:49
@ Unclear
Indicates that the position is unclear, typically displayed as an infinity symbol.
Definition PGN.hpp:53
@ WhiteModerateAdvantage
Indicates that white has a moderate advantage in this position.
Definition PGN.hpp:55
@ Inaccuracy
A mistake, typically displayed as ?.
Definition PGN.hpp:47
@ BlackModerateAdvantage
Indicates that black has a moderate advantage in this position.
Definition PGN.hpp:59
@ WhiteCrushingAdvantage
Indicates that white has a crushing advantage in this position (black should resign).
Definition PGN.hpp:57
@ WhiteInitiative
Indicates that white has the initiative in this position.
Definition PGN.hpp:63
@ Dubious
A questionable or dubious move, typically displayed as ?!.
Definition PGN.hpp:50
@ BlackCrushingAdvantage
Indicates that black has a crushing advantage in this position (white should resign).
Definition PGN.hpp:61
@ Null
A null annotation. Provided for usage as a placeholder value; should not appear in PGN files and has ...
Definition PGN.hpp:44
@ Forced
A forced or only move, typically displayed as a white square.
Definition PGN.hpp:51
@ Blunder
A blunder, typically displayed as ??.
Definition PGN.hpp:48
@ Drawish
Indicates that the position is drawish or double-sided, typically displayed as =.
Definition PGN.hpp:52
@ WhiteZugzwang
Indicates that white is in Zugzwang in this position.
Definition PGN.hpp:62
@ BlackSlightAdvantage
Indicates that black has a slight advantage in this position.
Definition PGN.hpp:58
@ BlackDecisiveAdvantage
Indicates that black has a decisive advantage in this position.
Definition PGN.hpp:60
std::vector< Move > Variation
Definition PGN.hpp:114
std::vector< NAG > nags
Definition PGN.hpp:111
std::vector< Variation > variations
Definition PGN.hpp:120
auto get_final_position() const -> Position
std::vector< Move > moves
Definition PGN.hpp:124
std::optional< game::Result > result
Definition PGN.hpp:90
std::unordered_map< string, string > metadata
Definition PGN.hpp:77