17#ifndef HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_ATTACKS_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__BITBOARD_ATTACKS_H_INCLUDED
20#include "pgnreader-config.h"
29#if BITBOARD_TABLES_HAVE_ELEMENTARY
33#if BITBOARD_TABLES_HAVE_BLACK_MAGIC
37#if BITBOARD_TABLES_HAVE_AARCH64_SVE2_BITPERM
41#if BITBOARD_TABLES_HAVE_X86_BMI2
83 static_assert(
static_cast<std::uint64_t
>(
Color::WHITE) == 0U);
84 static_assert(
static_cast<std::uint64_t
>(
Color::BLACK) == 8U);
113 static_assert(
static_cast<std::uint64_t
>(
Color::WHITE) == 0U);
114 static_assert(
static_cast<std::uint64_t
>(
Color::BLACK) == 8U);
147 template <Color pawnColor,
bool captureToRight>
150 return Attacks_Portable::getPawnAttackersMask<pawnColor, captureToRight>(capturable);
221#if BITBOARD_TABLES_HAVE_X86_BMI2
224#elif BITBOARD_TABLES_HAVE_AARCH64_SVE2_BITPERM
227#elif BITBOARD_TABLES_HAVE_BLACK_MAGIC
230#elif BITBOARD_TABLES_HAVE_ELEMENTARY
283#if BITBOARD_TABLES_HAVE_X86_BMI2
286#elif BITBOARD_TABLES_HAVE_AARCH64_SVE2_BITPERM
289#elif BITBOARD_TABLES_HAVE_BLACK_MAGIC
292#elif BITBOARD_TABLES_HAVE_ELEMENTARY
303#if BITBOARD_TABLES_HAVE_X86_BMI2
307#elif BITBOARD_TABLES_HAVE_AARCH64_SVE2_BITPERM
310#elif BITBOARD_TABLES_HAVE_BLACK_MAGIC
314#elif BITBOARD_TABLES_HAVE_ELEMENTARY
362 (Intercepts::getPinRestiction<true>(kingSq, src) & dstBit) !=
SquareSet { });
374 const Color turn)
noexcept
378#if BITBOARD_TABLES_HAVE_AARCH64_SVE2_BITPERM
391 const SquareSet attackers1 { horizVertHits & rooks };
392 const SquareSet attackers2 { diagHits & bishops };
403 attackers = (attackers1 | attackers2 | attackers3 | attackers4 | attackers5) & ~turnColorMask;
441#if 0 && HAVE_X86_AVX512F
442 Attacks_AVX512F::determineSliderCheckersAndPins(
452 const SquareSet opponentPieces { occupancyMask &~ turnColorMask };
460 out_checkers &= opponentPieces;
463 const SquareSet opponentPieces { occupancyMask ^ turnColorMask };
466#if HAVE_AARCH64_SVE2_BITPERM && 0
485 out_checkers &= opponentPieces;
490 const auto [ firstDiagHits, firstHVHits ] =
499 out_checkers |= firstDiagHits & bishops;
502 out_checkers |= firstHVHits & rooks;
510 const auto [ secondDiagHits, secondHVHits ] =
513 (occupancyMask &~ firstDiagHits) | (opponentPieces &~ epCapturable),
514 (occupancyMask &~ firstHVHits) | opponentPieces);
519 out_checkers &= opponentPieces;
521 pinners = ((rooks & secondHVHits) | (bishops & secondDiagHits)) & opponentPieces &~ out_checkers;
533 out_checkers |= firstHVHits & rooks;
537 out_checkers |= firstDiagHits & bishops;
539 out_checkers &= opponentPieces;
551 pinners = ((rooks & secondHVHits) | (bishops & secondDiagHits)) & opponentPieces &~ out_checkers;
560 out_pinnedPieces |= inBetween & (turnColorMask | epCapturable);
569 if ((out_checkers &~ epCapturable) !=
SquareSet { })
570 out_pinnedPieces |= epCapturable;
573 if ((epCapturable &~ out_pinnedPieces) !=
SquareSet { })
578 ((((epCapturable &
~SquareSet::column(0U)) >> 1U) |
579 ((epCapturable &
~SquareSet::column(7U)) << 1U))
581 & pawns & turnColorMask)
597 out_pinnedPieces |= epCapturable &~ epCaptureLegalMask;
601 if ((epCapturable & (
SquareSet::row(0U) << (
static_cast<std::uint64_t
>(kingSq) & 56U)))
608 epCapturable.firstSquare(),
609 occupancyMask &~ (adjacentPawns &~ adjacentPawnsMinus1)) };
612 const SquareSet oppRooks { rooks & ~turnColorMask };
614 const SquareSet pinnedEp { epCapturable &
615 (kingBit & exposedHorizLine).allIfAny() &
616 (oppRooks & exposedHorizLine).allIfAny() };
620 out_pinnedPieces |= pinnedEp;
657 static_assert(
static_cast<std::int8_t
>(
Color::WHITE) == 0);
658 static_assert(
static_cast<std::int8_t
>(
Color::BLACK) == 8);
661 std::int8_t pawnAdvanceShiftLeft = -9 + 2 *
static_cast<std::int8_t
>(turn);
664 attacks |= (pawns &~ SquareSet::column(0)).rotl(pawnAdvanceShiftLeft);
667 attacks |= (pawns &~ SquareSet::column(7)).rotl(pawnAdvanceShiftLeft + 2);
static SquareSet getQueenAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getQueenAttackMask() for documentation.
Definition bitboard-attacks-aarch64-sve2-bitperm.h:80
static std::pair< SquareSet, SquareSet > getBishopAndRookAttackMasks(Square sq, SquareSet occupancyMask) noexcept
Definition bitboard-attacks-aarch64-sve2-bitperm.h:106
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for documentation.
Definition bitboard-attacks-aarch64-sve2-bitperm.h:52
static void determineSliderCheckersAndPinners(Square kingSq, SquareSet occupancyMask, SquareSet rooks, SquareSet bishops, SquareSet opponentPieces, SquareSet epCapturable, SquareSet &out_checkers, SquareSet &out_pinners) noexcept
Definition bitboard-attacks-aarch64-sve2-bitperm.h:157
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for documentation.
Definition bitboard-attacks-aarch64-sve2-bitperm.h:66
static SquareSet determineAttackedSquares(SquareSet occupancyMask, SquareSet pawns, SquareSet knights, SquareSet bishops, SquareSet rooks, Square king, Color turn) noexcept
Definition bitboard-attacks-x86-avx512f.h:191
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for documentation.
Definition bitboard-attacks-x86-bmi2.h:53
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for documentation.
Definition bitboard-attacks-x86-bmi2.h:40
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for documentation.
Definition bitboard-attacks-black-magic.h:38
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for documentation.
Definition bitboard-attacks-black-magic.h:50
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for documentation.
Definition bitboard-attacks-elementary.h:38
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for documentation.
Definition bitboard-attacks-elementary.h:53
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getBishopAttackMask() for usage documentation.
static SquareSet getHorizRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
Returns horizontal rook attack mask.
Definition bitboard-attacks-portable.h:303
static SquareSet getPawnAttackMask(Square sq, Color pawnColor) noexcept
Definition bitboard-attacks-portable.h:211
static SquareSet getKingAttackMask(Square sq) noexcept
Definition bitboard-attacks-portable.h:266
static SquareSet getKnightAttackMask(Square sq) noexcept
Definition bitboard-attacks-portable.h:261
static SquareSet getPawnAttackerMask(Square sq, Color pawnColor) noexcept
Definition bitboard-attacks-portable.h:219
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
See Attacks::getRookAttackMask() for usage documentation.
Piece attack tables.
Definition bitboard-attacks.h:58
static SquareSet getBishopAttackMask(Square sq, SquareSet occupancyMask) noexcept
Returns the set of squares a bishop can attack, given also a set of occupied squares on board.
Definition bitboard-attacks.h:219
static SquareSet determineAttackers(const SquareSet occupancyMask, const SquareSet turnColorMask, const SquareSet pawns, const SquareSet knights, const SquareSet bishops, const SquareSet rooks, const SquareSet kings, const Square sq, const Color turn) noexcept
Definition bitboard-attacks.h:365
static SquareSet determineAttackedSquares(SquareSet occupancyMask, SquareSet pawns, SquareSet knights, SquareSet bishops, SquareSet rooks, Square king, Color turn) noexcept
Determines all attacked squares.
Definition bitboard-attacks.h:635
static SquareSet getPawnAttackMask(Square sq, Color pawnColor) noexcept
Returns a set of squares that a pawn can attack.
Definition bitboard-attacks.h:81
static SquareSet getPawnAttackerMask(Square sq, Color pawnColor) noexcept
Returns a set of squares from which a pawn can attack.
Definition bitboard-attacks.h:111
static SquareSet getQueenAttackMask(Square sq, SquareSet occupancyMask) noexcept
Definition bitboard-attacks.h:301
static constexpr SquareSet getPawnAttackersMask(SquareSet capturable) noexcept
For a given set of squares, returns the squares where pawns can attack the given squares.
Definition bitboard-attacks.h:148
static bool pinCheck(Square src, SquareSet dstBit, Square kingSq, SquareSet pinnedPieces) noexcept
Checks whether a move by a possibly pinned piece does not expose a check.
Definition bitboard-attacks.h:359
static SquareSet getKingAttackMask(Square sq) noexcept
Returns the set of squares a king can attack.
Definition bitboard-attacks.h:340
static SquareSet getRookAttackMask(Square sq, SquareSet occupancyMask) noexcept
Returns the set of squares a rook can attack, given also a set of occupied squares on board.
Definition bitboard-attacks.h:281
static SquareSet getKnightAttackMask(Square sq) noexcept
Returns the set of squares a knight can attack.
Definition bitboard-attacks.h:170
static void determineCheckersAndPins(SquareSet occupancyMask, SquareSet turnColorMask, SquareSet pawns, SquareSet knights, SquareSet bishops, SquareSet rooks, Square epSquare, SquareSet epCapturable, Square kingSq, Color turn, SquareSet &out_checkers, SquareSet &out_pinnedPieces) noexcept
Determines all checkers and pinners.
Definition bitboard-attacks.h:426
static SquareSet getInterceptSquares(Square kingSq, Square checkerSq) noexcept
Returns the set of squares that intercepts a check.
Definition bitboard-intercepts.h:66
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
static constexpr SquareSet all() noexcept
Returns a set of all squares.
Definition chessboard-types-squareset.h:460
static constexpr SquareSet row(RowColumn row) noexcept
Returns a set of squares in row number row.
Definition chessboard-types-squareset.h:485
constexpr SquareSet removeFirstSquare() const noexcept
Returns a square set with the first square (if any) removed.
Definition chessboard-types-squareset.h:124
Color
Color of a piece or side to move.
Definition chessboard-types.h:194
Square
Named square.
Definition chessboard-types.h:122
#define SQUARESET_ENUMERATE(sq, squareSet,...)
Enumerates all squares in a square set.
Definition chessboard-types-squareset.h:623
@ BLACK
Black piece or black side to move.
@ WHITE
White piece or white side to move.
Definition chessboard-types-squareset.h:30