Sliding Piece Attacks

From Chessprogramming wiki
Revision as of 00:59, 15 January 2022 by GerdIsenberg (talk | contribs)
Jump to: navigation, search

Home * Board Representation * Bitboards * Sliding Piece Attacks

Carina Jørgensen, Queen's Star [1]

This is basically about how to calculate attack-sets of sliding pieces for evaluation and move-generation purposes. While the attack-sets of pawn, king and knight are only dependent on their origin square, sliding pieces like rook, bishop or queen have to consider occupancy, as pieces may block the attack-ray in one particular direction.

Move targets

Move target sets from attack-sets require intersection

Single Sliding Piece Attacks

The single sliding piece, a rook, bishop or queen is determined by square index, likely from a bitscan of a piece-wise bitboard serialization of a sliding piece bitboard from a standard board-definition.

On an empty Board

Sliding piece attack sets or their disjoint subsets on lines or rays on an otherwise empty board are that simple than none sliding pieces. They are often base of further attack calculations.

Tinker's Approach

Brian Richardson proposed a move generation approach as used in Tinker based on rook or bishop attacks on the otherwise empty board [2]. While serializing all potential targets, he tests for legality inside the loop body, that is whether the inbetween squares of origin and target are empty. This is not in the "real" bitboard spirit to determine attack sets in advance rather than to test individual elements of a superset belonging to a set, but at least it allows traversing disjoint target sets i.e. for captures in quiescence search.

By Calculation

Some bit-twiddling ray-wise and line-wise approaches, unfortunately not always for all directions.

Bitfoot - A/B Bitboards
CFish - AVX2 Attacks
Shifted Bitboards

By Occupancy Lookup

Covering line-attacks in one run, magic bitboards even covers rook- and bishop-attacks in one run.

Sliding Piece Attacks in OliThink
BMI2 - PEXT Bitboards
SISSY Bitboards


Multiple Sliding Pieces

For bitsets with multiple sliding pieces one can apply a fill algorithm in each of the eight ray-directions to determine attacks. Since we keep disjoint directions, there is still a unique 1:1 relation from each bit of the target set to it's source square. This approach is great to determine target sets we may reach in two or more moves. One may use the union of rooks and queen(s), respectively bishops or queen(s) though.

AVX2 Dumb7Fill

If applied for move generation we better traverse directions rather than sliding pieces. Naturally this approach becomes less efficient, the less sliders are processed in parallel. Of course, one should avoid processing empty sets.

See also

Forum Posts


2000 ...

2005 ...

Re: BitBoard Tests Magic v Non-Rotated 32 Bits v 64 Bits by Harald Lüßen, CCC, August 24, 2007

2010 ...

2015 ...

2020 ...

External Links


Up one Level