|
HooverChessUtils_PgnReader 0.9.0
|
Portable implementations for attacks. More...
#include <bitboard-attacks-portable.h>
Static Public Member Functions | |
| static SquareSet | getPawnAttackMask (Square sq, Color pawnColor) noexcept |
| static SquareSet | getPawnAttackerMask (Square sq, Color pawnColor) noexcept |
| template<Color pawnColor, bool captureToRight> | |
| static constexpr SquareSet | getPawnAttackersMask (SquareSet capturable) noexcept |
| static SquareSet | getKnightAttackMask (Square sq) noexcept |
| static SquareSet | getKingAttackMask (Square sq) noexcept |
| static SquareSet | getBishopAttackMask (Square sq, SquareSet occupancyMask) noexcept |
See Attacks::getBishopAttackMask() for usage documentation. | |
| static SquareSet | getRookAttackMask (Square sq, SquareSet occupancyMask) noexcept |
See Attacks::getRookAttackMask() for usage documentation. | |
| static SquareSet | getHorizRookAttackMask (Square sq, SquareSet occupancyMask) noexcept |
| Returns horizontal rook attack mask. | |
Static Private Member Functions | |
| static SquareSet | getSliderAttackMaskHyperbola (SquareSet pieceBit, SquareSet occupancyMask, SquareSet rayMaskEx) noexcept |
| Calculate vertical, diagonal, or antidiagonal attack mask using the Hyperbola quintessence algorithm. | |
Portable implementations for attacks.
|
inlinestaticnoexcept |
See Attacks::getBishopAttackMask() for usage documentation.
| [in] | sq | Bishop square |
| [in] | occupancyMask | Set of occupied squares |
getSliderAttackMaskHyperbola() is used to implement this function.
|
inlinestaticnoexcept |
Returns horizontal rook attack mask.
| [in] | sq | Rook square |
| [in] | occupancyMask | Set of occupied squares |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
See Attacks::getRookAttackMask() for usage documentation.
| [in] | sq | Rook square |
| [in] | occupancyMask | Set of occupied squares |
getSliderAttackMaskHyperbola() is used to implement the vertical attack mask resolution.
The horizontal attack mask is resolved as follows:
sq row * 8U)
|
inlinestaticprivatenoexcept |
Calculate vertical, diagonal, or antidiagonal attack mask using the Hyperbola quintessence algorithm.
| [in] | pieceBit | Square set containing only the attacking piece |
| [in] | occupancyMask | Occupied squares |
| [in] | rayMaskEx | Forward/backward attack ray excluding the attacking piece. For example, the file of the rook not including the rook. |
Illustration
| Input | Return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
o = occupied squareshaded squares = rayMaskEx R = attacker | Squares marked with x = return |
The implementation uses a variation of the "o^(o-2r)" trick. First, the occupancy mask is AND'd with the ray mask.
| o | |||||||
| o | |||||||
| o |
Then, two copies are taken: one as is (left side) and one mirrored vertically (right side):
|
|
The attacking piece is subtracted from the boards. Note that the attacking piece bit is also flipped vertically in the right-side board.
|
|
The right-side board is flipped vertically again.
|
|
The left-side and right-side boards are then XOR'd together.
| o | o | x | |||||
| o | o | x | o | o | o | o | o |
| o | o | x | o | o | o | o | o |
| o | o | x | o | o | o | o | o |
| o | o | x |
and the result is AND'd with the ray mask. This gives the final result.
The XOR operation isolates the bits that change in the subtraction operation. This is the reason why this algorithm works.