HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
hoover_chess_utils::pgn_reader::Attacks Class Reference

Piece attack tables. More...

#include <bitboard-attacks.h>

Static Public Member Functions

static SquareSet getPawnAttackMask (Square sq, Color pawnColor) noexcept
 Returns a set of squares that a pawn can attack.
 
static SquareSet getPawnAttackerMask (Square sq, Color pawnColor) noexcept
 Returns a set of squares from which a pawn can attack.
 
template<Color pawnColor, bool captureToRight>
static constexpr SquareSet getPawnAttackersMask (SquareSet capturable) noexcept
 For a given set of squares, returns the squares where pawns can attack the given squares.
 
static SquareSet getKnightAttackMask (Square sq) noexcept
 Returns the set of squares a knight can attack.
 
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.
 
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.
 
static SquareSet getQueenAttackMask (Square sq, SquareSet occupancyMask) noexcept
 
static SquareSet getKingAttackMask (Square sq) noexcept
 Returns the set of squares a king can attack.
 
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.
 
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
 
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.
 
static SquareSet determineAttackedSquares (SquareSet occupancyMask, SquareSet pawns, SquareSet knights, SquareSet bishops, SquareSet rooks, Square king, Color turn) noexcept
 Determines all attacked squares.
 

Detailed Description

Piece attack tables.

Member Function Documentation

◆ determineAttackedSquares()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::determineAttackedSquares ( SquareSet  occupancyMask,
SquareSet  pawns,
SquareSet  knights,
SquareSet  bishops,
SquareSet  rooks,
Square  king,
Color  turn 
)
inlinestaticnoexcept

Determines all attacked squares.

Parameters
[in]occupancyMaskAll occupied squares. These block slider attacks
[in]pawnsAttacking pawns
[in]knightsAttacking knights
[in]bishopsAttacking bishops and queens
[in]rooksAttacking rooks and queens
[in]kingAttacking king
[in]turnSide to move (determines pawn attacking direction)
Returns
All attacked squares

◆ determineAttackers()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::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 
)
inlinestaticnoexcept

◆ determineCheckersAndPins()

static void hoover_chess_utils::pgn_reader::Attacks::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 
)
inlinestaticnoexcept

Determines all checkers and pinners.

Parameters
[in]occupancyMaskAll occupied squares. These block slider attacks
[in]turnColorMaskPieces of the side to move
[in]pawnsAll pawns
[in]knightsAll knights
[in]bishopsAll bishops and queens
[in]rooksAll rooks and queens
[in]epSquareEn passant square or Square::NONE
[in]epCapturableEn passant capturable pawn or SquareSet::none()
[in]kingSqKing of side to move
[in]turnSide to move
[out]out_checkersSet of checking pieces
[out]out_pinnedPiecesSet of pinned pieces. The capturable en passant pawn is included if it is pinned diagonally.
Remarks
A diagonally pinned en passant capturable pawn cannot be captured due to the pin.

◆ getBishopAttackMask()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::getBishopAttackMask ( Square  sq,
SquareSet  occupancyMask 
)
inlinestaticnoexcept

Returns the set of squares a bishop can attack, given also a set of occupied squares on board.

Parameters
[in]sqBishop square
[in]occupancyMaskSet of occupied squares
Returns
Set of attacked squares

Per every diagonal direction from sq, the set of attacked squares is all squares between sq and the first occupied square (if any) including the occupied square. If no occupied squares are in that direction, then all squares in that direction are included.

Occupancy of sq is ignored.

The implementation used is as follows:

Build condition Description
HAVE_X86_BMI2 Implementation using Attacks_BMI2::getBishopAttackMask()
Otherwise Implementation using Attacks_Portable::getBishopAttackMask()

Example

o
B
o
oo
o

◆ getKingAttackMask()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::getKingAttackMask ( Square  sq)
inlinestaticnoexcept

Returns the set of squares a king can attack.

Parameters
[in]sqKing square
Returns
Set of attacked squares
K

◆ getKnightAttackMask()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::getKnightAttackMask ( Square  sq)
inlinestaticnoexcept

Returns the set of squares a knight can attack.

Parameters
[in]sqKnight square
Returns
Set of attacked squares

Example

N

◆ getPawnAttackerMask()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::getPawnAttackerMask ( Square  sq,
Color  pawnColor 
)
inlinestaticnoexcept

Returns a set of squares from which a pawn can attack.

Parameters
[in]sqAttacked square
[in]pawnColorColor of the attacking pawn
Returns
Set of squares from which a pawn can attack sq

Example

sq
wPwP
Remarks
Validity of pawn position is not assumed. Hence, attacker squares are provided for white pawns on 2nd rank (pawns on 1st) and black pawns on 7th rank (pawns on 8th).

◆ getPawnAttackersMask()

template<Color pawnColor, bool captureToRight>
static constexpr SquareSet hoover_chess_utils::pgn_reader::Attacks::getPawnAttackersMask ( SquareSet  capturable)
inlinestaticconstexprnoexcept

For a given set of squares, returns the squares where pawns can attack the given squares.

Template Parameters
pawnColorColor of the attacking pawns
captureToRightWhether pawns are capturing towards right (increasing column number)
Parameters
[in]capturableCapturable squares. Typically all opponent's pawns and pieces
Returns
Set of pawn attacker squares

Example (white pawn, capture right)

ccccc
cccwPccwP
wPwPcwPwPc
ccc
cwPwPwP
wP
Remarks
Validity of pawn position is not assumed. Hence, attacker squares are provided for white pawns on 2nd rank (pawns on 1st) and black pawns on 7th rank (pawns on 8th).
See also
generateMovesForPawnsTempl()

◆ getPawnAttackMask()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::getPawnAttackMask ( Square  sq,
Color  pawnColor 
)
inlinestaticnoexcept

Returns a set of squares that a pawn can attack.

Parameters
[in]sqPawn square
[in]pawnColorColor of the pawn
Returns
Set of squares the pawn can attack

Example

wP
Remarks
Validity of pawn position is not assumed. Hence, attack squares are provided for white pawns on 1st rank and black pawns on 8th rank.

◆ getQueenAttackMask()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::getQueenAttackMask ( Square  sq,
SquareSet  occupancyMask 
)
inlinestaticnoexcept

◆ getRookAttackMask()

static SquareSet hoover_chess_utils::pgn_reader::Attacks::getRookAttackMask ( Square  sq,
SquareSet  occupancyMask 
)
inlinestaticnoexcept

Returns the set of squares a rook can attack, given also a set of occupied squares on board.

Parameters
[in]sqRook square
[in]occupancyMaskSet of occupied squares
Returns
Set of attacked squares

Per horizontal/vertical direction from sq, the set of attacked squares is all squares between sq and the first occupied square (if any) including the occupied square. If no occupied squares are in that direction, then all squares in that direction are included.

Occupancy of sq is ignored.

The implementation used is as follows:

Build condition Description
HAVE_X86_BMI2 Implementation using Attacks_BMI2::getRookAttackMask()
Otherwise Implementation using Attacks_Portable::getRookAttackMask()

Example

o
Roo
oo

◆ pinCheck()

static bool hoover_chess_utils::pgn_reader::Attacks::pinCheck ( Square  src,
SquareSet  dstBit,
Square  kingSq,
SquareSet  pinnedPieces 
)
inlinestaticnoexcept

Checks whether a move by a possibly pinned piece does not expose a check.

Parameters
[in]srcSource square
[in]dstBitDestination square bit
[in]kingSqKing square
[in]pinnedPiecesSet of pinned pieces
Returns
Move legality (from the point of pin)

In case the piece on src is not pinned, this function will always return true.

In case the piece on src is pinned, this function checks whether the piece moves directly towards or away from the king.


The documentation for this class was generated from the following file: