HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
position-compress-fixed.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 2021-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__POSITION_COMPRESS_FIXED_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__POSITION_COMPRESS_FIXED_H_INCLUDED
19
20#include <array>
21#include <bit>
22#include <cstdint>
23
24
26{
27
28class ChessBoard;
29
32
38{
41
43 WHITE_BISHOP = 1U,
44
47
49 WHITE_QUEEN = 3U, // note: BISHOP | ROOK_CANNOT_CASTLE
50
52 WHITE_KNIGHT = 4U,
53
55 WHITE_PAWN = 5U,
56
58 WHITE_ROOK_CAN_CASTLE = 6U, // note: ROOK_CANNOT_CASTLE | 4
59
62
66 EP_PAWN = 8U,
67
69 BLACK_BISHOP = 9U,
70
73
75 BLACK_QUEEN = 11U, // note: BISHOP | ROOK_CANNOT_CASTLE
76
78 BLACK_KNIGHT = 12U,
79
81 BLACK_PAWN = 13U,
82
84 BLACK_ROOK_CAN_CASTLE = 14U, // note: ROOK_CANNOT_CASTLE | 4
85
87 BLACK_KING = 15U,
88};
89
155{
159 std::uint64_t occupancy;
160
162 std::array<std::uint32_t, 4U> dataPlanes;
163};
164
182{
183 using RawCompareType = std::array<std::uint64_t, 3U>;
184 static_assert(sizeof(RawCompareType) == sizeof(CompressedPosition_FixedLength));
185
186 const RawCompareType *p1 { std::bit_cast<const RawCompareType *>(&lhs) };
187 const RawCompareType *p2 { std::bit_cast<const RawCompareType *>(&rhs) };
188
189 return *p1 <=> *p2;
190}
191
198{
199 using RawCompareType = std::array<std::uint64_t, 3U>;
200 static_assert(sizeof(RawCompareType) == sizeof(CompressedPosition_FixedLength));
201
202 const RawCompareType *p1 { std::bit_cast<const RawCompareType *>(&lhs) };
203 const RawCompareType *p2 { std::bit_cast<const RawCompareType *>(&rhs) };
204
205 return *p1 == *p2;
206}
207
213{
214private:
217
218public:
227 static void compress(const ChessBoard &board, CompressedPosition_FixedLength &out_compressedPosition);
228
241 static void decompress(const CompressedPosition_FixedLength &compressedPosition, std::uint8_t halfMoveClock, std::uint32_t moveNum, pgn_reader::ChessBoard &out_board);
242};
243
245
246}
247
248#endif
249
The chessboard.
Definition chessboard.h:589
Position compressor that produces fixed-length output (192 bits).
Definition position-compress-fixed.h:213
static void compress(const ChessBoard &board, CompressedPosition_FixedLength &out_compressedPosition)
Compresses a chess position with at most 32 pieces.
static void decompress(const CompressedPosition_FixedLength &compressedPosition, std::uint8_t halfMoveClock, std::uint32_t moveNum, pgn_reader::ChessBoard &out_board)
Compresses a chess position with at most 32 pieces.
bool operator==(const CompressedPosition_FixedLength &lhs, const CompressedPosition_FixedLength &rhs) noexcept
Equality comparison operator.
Definition position-compress-fixed.h:197
auto operator<=>(const CompressedPosition_FixedLength &lhs, const CompressedPosition_FixedLength &rhs) noexcept
Three-way comparison operator (spaceship). The comparison provides strong ordering.
Definition position-compress-fixed.h:181
CompressedPosition_PieceEncoding
Compressed piece encoding for fixed-length compressed position.
Definition position-compress-fixed.h:38
Definition chessboard-types-squareset.h:30
A position encoded in 192 bits.
Definition position-compress-fixed.h:155
std::uint64_t occupancy
Occupancy mask.
Definition position-compress-fixed.h:159
std::array< std::uint32_t, 4U > dataPlanes
Data planes.
Definition position-compress-fixed.h:162