17#ifndef HOOVER_CHESS_UTILS__PGN_READER__CHESSBOARD_TYPES_SQUARESET_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__CHESSBOARD_TYPES_SQUARESET_H_INCLUDED
48 constexpr inline SquareSet(std::same_as<Square>
auto... squares) noexcept :
51 std::uint64_t bitmask { };
52 for (
auto sq : std::initializer_list<
Square>{ squares... })
57 [[assume(sqRaw < 64U)]];
59 bitmask |= UINT64_C(1) << sqRaw;
81 explicit constexpr inline SquareSet(std::uint64_t mask) noexcept :
87 explicit constexpr inline operator std::uint64_t() const noexcept
95 constexpr inline std::uint_fast8_t
popcount() const noexcept
462 return SquareSet { 0xFF'FF'FF'FF'FF'FF'FF'FFU };
474 [[assume(col <= 7U)]];
476 return SquareSet { std::uint64_t { 0x01'01'01'01'01'01'01'01U } << col };
488 [[assume(
row <= 7U)]];
490 return SquareSet { std::uint64_t { 0x00'00'00'00'00'00'00'FFU } << (
row * 8U) };
525 const auto shift { col + (
row * 8U) };
526 [[assume(shift <= 63U)]];
528 return SquareSet { std::uint64_t { 1U } << shift };
534 assert(
static_cast<std::uint8_t
>(sq) <= 63U);
535 [[assume(
static_cast<std::uint8_t
>(sq) <= 63U)]];
582#define SQUARESET_ENUMERATE_INTERNAL(sq, squareSet, tmpMask, ...) \
585 SquareSet tmpMask { squareSet }; \
589 const Square sq { tmpMask.firstSquare() }; \
591 if (sq > Square::H8) \
594 tmpMask &= ~SquareSet::square(sq); \
623#define SQUARESET_ENUMERATE(sq, squareSet, ...) \
624 SQUARESET_ENUMERATE_INTERNAL(sq, squareSet, squareset_enumerate_internal_mask, __VA_ARGS__)
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
static constexpr SquareSet column(RowColumn col) noexcept
Returns a set of squares in column number col.
Definition chessboard-types-squareset.h:471
constexpr SquareSet operator&(SquareSet other) const noexcept
Returns an intersection with another square set.
Definition chessboard-types-squareset.h:139
constexpr SquareSet(std::uint64_t mask) noexcept
Cast operator.
Definition chessboard-types-squareset.h:81
constexpr SquareSet rotr(std::int_fast8_t shift) const noexcept
Rotates right element-wise (circular shift)
Definition chessboard-types-squareset.h:308
constexpr SquareSet()=default
Default constructor (empty set)
SquareSet parallelExtract(SquareSet extractMask) noexcept
Extracts squares from *this using extraction mask. The extracted squares are mapped as follows:
SquareSet parallelDeposit(SquareSet extractMask) noexcept
Maps squares from *this using extraction mask. Squares are mapped as follows: mapped as follows:
constexpr SquareSet allIfAny() const noexcept
Conditional.
Definition chessboard-types-squareset.h:547
constexpr SquareSet & operator|=(SquareSet other) noexcept
Assignment operator (union). Shorthand for x = x | other.
Definition chessboard-types-squareset.h:193
constexpr SquareSet allIfNone() const noexcept
Conditional.
Definition chessboard-types-squareset.h:541
constexpr Square firstSquare() const noexcept
Returns the first (lowest-value) square in the set or Square::NONE if the set is empty.
Definition chessboard-types-squareset.h:105
static constexpr SquareSet squareOrNone(Square sq) noexcept
Returns a set of 0 or 1 squares.
Definition chessboard-types-squareset.h:509
constexpr SquareSet(std::same_as< Square > auto... squares) noexcept
Constructor from a list of Squares.
Definition chessboard-types-squareset.h:48
constexpr SquareSet(SquareSet &&)=default
Default move constructor.
static constexpr SquareSet all() noexcept
Returns a set of all squares.
Definition chessboard-types-squareset.h:460
constexpr SquareSet rotl(std::int_fast8_t shift) const noexcept
Rotates left element-wise (circular shift)
Definition chessboard-types-squareset.h:287
constexpr std::uint_fast8_t popcount() const noexcept
Returns the number of squares in the set.
Definition chessboard-types-squareset.h:95
constexpr SquareSet & operator=(const SquareSet &)=default
Default copy assignment.
static constexpr SquareSet square(Square sq) noexcept
Returns a set of single square.
Definition chessboard-types-squareset.h:497
std::uint64_t m_bitmask
The set of squares. Bit N set in the mask represents square N included in the set....
Definition chessboard-types-squareset.h:39
static constexpr SquareSet row(RowColumn row) noexcept
Returns a set of squares in row number row.
Definition chessboard-types-squareset.h:485
static constexpr SquareSet square(RowColumn col, RowColumn row) noexcept
Returns a set of single square specified by column and row numbers.
Definition chessboard-types-squareset.h:520
constexpr SquareSet operator<<=(std::uint_fast8_t shift) noexcept
Assignment operator (left shift). Shorthand for x = x << shift.
Definition chessboard-types-squareset.h:317
constexpr SquareSet removeFirstSquare() const noexcept
Returns a square set with the first square (if any) removed.
Definition chessboard-types-squareset.h:124
constexpr SquareSet operator<<(std::uint_fast8_t shift) const noexcept
Shifts left element-wise.
Definition chessboard-types-squareset.h:242
constexpr Square lastSquare() const noexcept
Returns the last (highest-value) square in the set or Square::NONE if the set is empty.
Definition chessboard-types-squareset.h:115
constexpr SquareSet & operator^=(SquareSet other) noexcept
Assignment operator (union). Shorthand for x = x ^ other.
Definition chessboard-types-squareset.h:203
constexpr bool operator!=(SquareSet other) const noexcept
Comparison operator (non-equality). Returns true if *this does not equal to other.
Definition chessboard-types-squareset.h:356
constexpr SquareSet operator>>(std::uint_fast8_t shift) const noexcept
Shifts right element-wise.
Definition chessboard-types-squareset.h:266
constexpr SquareSet operator>>=(std::uint_fast8_t shift) noexcept
Assignment operator (right shift). Shorthand for x = x >> shift.
Definition chessboard-types-squareset.h:327
constexpr SquareSet operator~() const noexcept
Returns the complement of *this.
Definition chessboard-types-squareset.h:218
constexpr SquareSet operator|(SquareSet other) const noexcept
Returns an union with another square set.
Definition chessboard-types-squareset.h:154
constexpr SquareSet(const SquareSet &)=default
Default copy constructor.
constexpr bool operator==(SquareSet other) const noexcept
Comparison operator (equality). Returns true if *this equals to other.
Definition chessboard-types-squareset.h:346
constexpr ~SquareSet()=default
Default destructor.
constexpr SquareSet & operator&=(SquareSet other) noexcept
Assignment operator (union). Shorthand for x = x & other.
Definition chessboard-types-squareset.h:183
constexpr SquareSet flipVert() const noexcept
Flips the squares vertically (upside down)
Definition chessboard-types-squareset.h:336
static constexpr SquareSet none() noexcept
Returns an empty set.
Definition chessboard-types-squareset.h:452
constexpr bool isMember(Square sq) const noexcept
Checks whether a valid square is in the set.
Definition chessboard-types-squareset.h:532
constexpr SquareSet operator^(SquareSet other) const noexcept
Returns an exclusive or with another square set. Formally, when square s is included in exactly one o...
Definition chessboard-types-squareset.h:174
std::uint_fast8_t SquareUnderlyingType
Underlying type of Square
Definition chessboard-types.h:38
Square
Named square.
Definition chessboard-types.h:122
RowColumnUnderlyingType RowColumn
Row/column coordinate type. Valid range: [0, 7] signifying ranks 1–8 (as rows) or files A–H (as colum...
Definition chessboard-types.h:92
@ NONE
Token for 'no' square.
Definition chessboard-types-squareset.h:30