HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
pgnreader-types.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 2022-2025 Sami Kiminki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef HOOVER_CHESS_UTILS__PGN_READER__PGNREADER_TYPES_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__PGNREADER_TYPES_H_INCLUDED
19
20#include <cinttypes>
21
22#include "chessboard-types.h"
23
25{
26
29
31enum class PgnResult : std::uint_fast8_t
32{
35
38
40 DRAW,
41
43 UNKNOWN,
44};
45
51constexpr inline std::uint_fast32_t makePlyNum(std::uint_fast32_t moveNum, Color color) noexcept
52{
53 assert(moveNum >= 1U);
54 [[assume(moveNum >= 1U)]];
55
56 assert(moveNum <= UINT32_C(0x80'00'00'00));
57 [[assume(moveNum <= UINT32_C(0x80'00'00'00))]];
58
59 return (moveNum * 2U) - (color == Color::WHITE ? 2U : 1U);
60}
61
66constexpr inline Color colorOfPly(std::uint_fast32_t plyNum) noexcept
67{
68 return (plyNum & 1U) ? Color::BLACK : Color::WHITE;
69}
70
75constexpr inline std::uint_fast32_t moveNumOfPly(std::uint_fast32_t plyNum) noexcept
76{
77 return 1U + (plyNum / 2U);
78}
79
81
82}
83
84#endif
constexpr Color colorOfPly(std::uint_fast32_t plyNum) noexcept
Returns side to move for a ply number.
Definition pgnreader-types.h:66
constexpr std::uint_fast32_t moveNumOfPly(std::uint_fast32_t plyNum) noexcept
Computes the full move for a ply number.
Definition pgnreader-types.h:75
PgnResult
Game result.
Definition pgnreader-types.h:32
constexpr std::uint_fast32_t makePlyNum(std::uint_fast32_t moveNum, Color color) noexcept
Computes the ply number from full move number and side to move.
Definition pgnreader-types.h:51
Color
Color of a piece or side to move.
Definition chessboard-types.h:194
@ BLACK
Black piece or black side to move.
@ WHITE
White piece or white side to move.
Definition chessboard-types-squareset.h:30