17#ifndef HOOVER_CHESS_UTILS__PGN_READER__CHESSBOARD_MOVEGEN_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__CHESSBOARD_MOVEGEN_H_INCLUDED
44 static std::array<MoveGenFunctions, 3U>
m_fns;
49 const std::size_t index {
static_cast<std::size_t
>(type) };
51 assert(index <
m_fns.size());
58template <
bool shortCastling>
64 static constexpr std::uint8_t kingTargetColumn { 2U };
65 static constexpr std::uint8_t rookTargetColumn { 3U };
71 static constexpr std::uint8_t kingTargetColumn { 6U };
72 static constexpr std::uint8_t rookTargetColumn { 5U };
78 static_assert(std::is_same_v<UnderlyingType, PieceUnderlyingType>);
80 constexpr UnderlyingType bias =
91 (
static_cast<UnderlyingType
>(
Piece::ROOK) + bias) ==
143template <MoveGenType type>
149 static_cast<void>(kingSq);
150 static_cast<void>(checkers);
151 static_cast<void>(dst);
174template <MoveGenType type,
typename MoveStoreFn,
bool shortCastling>
178 typename MoveStoreFn::Store &store)
noexcept
185 static_assert(
static_cast<std::uint8_t
>(
Color::WHITE) == 0U);
186 static_assert(
static_cast<std::uint8_t
>(
Color::BLACK) == 8U);
190 const Color turn { board.getTurn() };
191 const Square sqRook { board.getCastlingRook(turn, shortCastling) };
197 const std::uint8_t targetRowAdd = (-
static_cast<std::uint8_t
>(turn)) & 63U;
198 const Square sqKingTarget {
static_cast<std::uint8_t
>(CastlingSideSpecifics::kingTargetColumn + targetRowAdd) };
199 const Square sqRookTarget {
static_cast<std::uint8_t
>(CastlingSideSpecifics::rookTargetColumn + targetRowAdd) };
206 (kingPathHalfOpen | rookPathHalfOpen) &~
SquareSet { board.getKingInTurn(), sqRook } };
208 if (((requiredEmptySquares & board.getOccupancyMask()) |
209 (
SquareSet { sqRook } & board.getPinnedPieces()) |
210 (kingPathHalfOpen & attackedSquares)
214 if constexpr (shortCastling)
The chessboard.
Definition chessboard.h:589
static SquareSet getInterceptSquares(Square kingSq, Square checkerSq) noexcept
Returns the set of squares that intercepts a check.
Definition bitboard-intercepts.h:66
Definition chessboard-movegen.h:42
static std::array< MoveGenFunctions, 3U > m_fns
Definition chessboard-movegen.h:44
static const MoveGenFunctions & getFunctions(MoveGenType type) noexcept
Definition chessboard-movegen.h:47
A legal move. Important: see the note!
Definition chessboard.h:198
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
constexpr SquareSet allIfAny() const noexcept
Conditional.
Definition chessboard-types-squareset.h:547
static constexpr SquareSet all() noexcept
Returns a set of all squares.
Definition chessboard-types-squareset.h:460
MoveTypeAndPromotion
Move type (4 bits, range: 0..15)
Definition chessboard.h:91
Piece
Named piece.
Definition chessboard-types.h:204
Color
Color of a piece or side to move.
Definition chessboard-types.h:194
Square
Named square.
Definition chessboard-types.h:122
std::uint_fast8_t PieceUnderlyingType
Underlying type of Piece
Definition chessboard-types.h:56
@ PROMO_ROOK
Pawn promotion to rook.
@ PROMO_BISHOP
Pawn promotion to bishop.
@ CASTLING_SHORT
Short castling.
@ PROMO_KNIGHT
Pawn promotion to knight.
@ CASTLING_LONG
Long castling.
@ BLACK
Black piece or black side to move.
@ WHITE
White piece or white side to move.
@ NONE
Token for 'no' square.
MoveGenType
Move generator type.
Definition chessboard.h:519
@ NO_CHECK
Move generator for when the king is not in check. All moves are considered.
Definition chessboard-types-squareset.h:30
void generateMovesForCastlingStoreFnTempl(const ChessBoard &board, SquareSet attackedSquares, typename MoveStoreFn::Store &store) noexcept
Generates the legal castling move, if any.
Definition chessboard-movegen.h:175
constexpr MoveTypeAndPromotion pieceToTypeAndPromotion(Piece promotion) noexcept
Definition chessboard-movegen.h:75
SquareSet blocksAllChecksMaskTempl(Square kingSq, SquareSet checkers, Square dst) noexcept
constexpr SquareSet blocksAllChecksMaskTempl< MoveGenType::NO_CHECK >(Square kingSq, SquareSet checkers, Square dst) noexcept
Definition chessboard-movegen.h:147
SquareSet blocksAllChecksMaskTempl< MoveGenType::CHECK >(Square kingSq, SquareSet checkers, Square dst) noexcept
Definition chessboard-movegen.h:157
Definition chessboard-movegen.h:115
constexpr SquareSet operator()() const noexcept
Definition chessboard-movegen.h:116
Definition chessboard-movegen.h:59
Move generator functions.
Definition chessboard.h:1490
Definition chessboard-movegen.h:123
SquareSet m_legalDestinations
Definition chessboard-movegen.h:124
~ParametrizedLegalDestinationType()=default
ParametrizedLegalDestinationType(ParametrizedLegalDestinationType &&)=default
ParametrizedLegalDestinationType(const ParametrizedLegalDestinationType &)=default
constexpr SquareSet operator()() const noexcept
Definition chessboard-movegen.h:137
ParametrizedLegalDestinationType & operator=(const ParametrizedLegalDestinationType &) &=default
constexpr ParametrizedLegalDestinationType(SquareSet legalDestinations) noexcept
Definition chessboard-movegen.h:126