HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
chessboard-priv.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 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__CHESSBOARD_PRIV_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__CHESSBOARD_PRIV_H_INCLUDED
19
20#include "chessboard.h"
21#include "chessboard-types.h"
22
23
25{
26
28{
30 {
31 return *this;
32 }
33};
34
36{
37private:
38 bool m_legalMoves { };
39
40public:
42 {
43 m_legalMoves = true;
44 return *this;
45 }
46
47 inline LegalMoveDetectorIterator &operator += (std::uint8_t amount) noexcept
48 {
49 m_legalMoves = m_legalMoves || (amount != 0U);
50 return *this;
51 }
52
57
58 bool hasLegalMoves() const noexcept
59 {
60 return m_legalMoves;
61 }
62};
63
65{
66private:
67 std::uint8_t m_numLegalMoves { };
68
69public:
71 {
73 return *this;
74 }
75
76 inline LegalMoveCounterIterator &operator += (std::uint8_t amount) noexcept
77 {
78 m_numLegalMoves += amount;
79 return *this;
80 }
81
86
87 std::size_t getNumberOfLegalMoves() const noexcept
88 {
89 return m_numLegalMoves;
90 }
91};
92
93template <typename IteratorType>
95{
96 using Store = IteratorType;
97
98 inline static void storeMove(IteratorType &i, Move m) noexcept
99 {
100 *i = m;
101 ++i;
102 }
103};
104
106{
107 using Store = Move;
108
109 inline static void storeMove(Move &ret, Move m) noexcept
110 {
111 if (ret == Move::illegalNoMove()) [[likely]]
112 ret = m;
113 else
115 }
116};
117
119{
120 using Store = Move;
121
122 inline static void storeMove(Move &ret, Move m) noexcept
123 {
124 ret = m;
125 }
126};
127
128
129template <typename IteratorType>
131{
132 using Iterator = IteratorType;
133
134 // Returns true when further move generation can still add moves. This is
135 // mainly intended to allow movegen with LegalMoveDetectorIterator to exit
136 // early after a legal move has been found.
137 static constexpr bool moveGenCompleted(Iterator) noexcept;
138
139 // Whether this iterator stores moves (MoveList::iterator) or
140 // whether it's just interested on whether there is a move
141 // (LegalMoveCounterIterator, LegalMoveDetectorIterator). This is used to
142 // skip creating moves is addMoveIfLegal* functions if the actual moves
143 // don't matter.
144 static constexpr bool storesMoves() noexcept;
145};
146
147template <>
149{
150 using Iterator = MoveList::iterator;
151
152 static constexpr bool canCompleteEarly { false };
153
154 static constexpr bool storesMoves() noexcept
155 {
156 return true;
157 }
158};
159
160template <>
162{
164
165 static constexpr bool canCompleteEarly { false };
166
167 static constexpr bool storesMoves() noexcept
168 {
169 return false;
170 }
171};
172
173template <>
175{
177
178 static constexpr bool canCompleteEarly { true };
179
180 static constexpr bool storesMoves() noexcept
181 {
182 return false;
183 }
184};
185
186}
187
188#endif
std::uint8_t m_numLegalMoves
Definition chessboard-priv.h:67
std::size_t getNumberOfLegalMoves() const noexcept
Definition chessboard-priv.h:87
LegalMoveCounterIterator & operator++() noexcept
Definition chessboard-priv.h:70
LegalMoveCounterIterator & operator+=(std::uint8_t amount) noexcept
Definition chessboard-priv.h:76
DummyMoveIteratorDereference operator*() noexcept
Definition chessboard-priv.h:82
LegalMoveDetectorIterator & operator++() noexcept
Definition chessboard-priv.h:41
bool m_legalMoves
Definition chessboard-priv.h:38
bool hasLegalMoves() const noexcept
Definition chessboard-priv.h:58
DummyMoveIteratorDereference operator*() noexcept
Definition chessboard-priv.h:53
LegalMoveDetectorIterator & operator+=(std::uint8_t amount) noexcept
Definition chessboard-priv.h:47
A legal move. Important: see the note!
Definition chessboard.h:198
static constexpr Move illegalNoMove() noexcept
Token for illegal move: no moves generated.
Definition chessboard.h:429
static constexpr Move illegalAmbiguousMove() noexcept
Token for illegal move: ambiguous move generation.
Definition chessboard.h:437
std::array< CompactMove, 256U > MoveList
Move list returned by ChessBoard::generateMoves().
Definition chessboard.h:508
Definition chessboard-types-squareset.h:30
DummyMoveIteratorDereference & operator=(Move) noexcept
Definition chessboard-priv.h:29
IteratorType Store
Definition chessboard-priv.h:96
static void storeMove(IteratorType &i, Move m) noexcept
Definition chessboard-priv.h:98
static constexpr bool storesMoves() noexcept
Definition chessboard-priv.h:167
static constexpr bool storesMoves() noexcept
Definition chessboard-priv.h:180
MoveList::iterator Iterator
Definition chessboard-priv.h:150
static constexpr bool storesMoves() noexcept
Definition chessboard-priv.h:154
static constexpr bool storesMoves() noexcept
static constexpr bool moveGenCompleted(Iterator) noexcept
IteratorType Iterator
Definition chessboard-priv.h:132
static void storeMove(Move &ret, Move m) noexcept
Definition chessboard-priv.h:109
static void storeMove(Move &ret, Move m) noexcept
Definition chessboard-priv.h:122