Sliding Piece Attacks

Home * Board Representation * Bitboards * Sliding Piece Attacks



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.
 * with opponent pieces for captures
 * with all empty squares for quiet moves

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.
 * Attacks on the otherwise empty Board

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. 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.
 * Blockers and Beyond
 * Classical Approach
 * Bitfoot - A/B Bitboards


 * Subtracting a Rook from a Blocking Piece
 * Reverse Bitboards
 * Hyperbola Quintessence
 * Obstruction Difference
 * SBAMG
 * Exploding Bitboards

By Occupancy Lookup
Covering line-attacks in one run, magic bitboards even covers rook- and bishop-attacks in one run.
 * First Rank Attacks
 * Occupancy of any Line
 * Rotated Bitboards
 * Rotated Indices
 * Kindergarten Bitboards
 * Sliding Piece Attacks in OliThink


 * Hashing Dictionaries
 * Congruent Modulo Bitboards
 * Magic Bitboards
 * BMI2 - PEXT Bitboards


 * Sherwin Bitboards
 * SISSY Bitboards


 * Titboards

Miscellaneous
=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.
 * The Switch Approach
 * SIMD Techniques
 * Hiding the Implementation
 * Dumb7Fill
 * AVX2 Dumb7Fill


 * Kogge-Stone Algorithm
 * Fill by Subtraction

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=
 * Efficient Generation of Sliding Piece Attacks, a Summary of selected attack generation techniques, a short Talk by Gerd Isenberg from the Workshop Chess and Mathematics, Dresden, November 21st and 22nd, 2008
 * Combinatorial Logic - Combinatorial Attacks
 * Sequential Logic - Sequential Rook Attack
 * Vector Attacks

=Forum Posts=

1999

 * Re: How do you represent chess boards in your chess programms by Sven Reichard, CCC, September 29, 1999

2000 ...

 * Movegen Re: Bitmap Type Re: Tinker 81 secs Re: Testing speed by Brian Richardson, CCC, April 24, 2000
 * An idea to generate rook moves without rotated BBs by Severi Salminen, CCC, October 22, 2000
 * sliding attacks in three #define by Rasjid Chan, CCC, April 09, 2004

2005 ...

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


 * Yet another bitboard attack generator by Miguel A. Ballicora, CCC, October 28, 2009
 * Other attack generator just for good measure ... C++ only... by Filip Tvrzsky, CCC, October 29, 2009
 * Caching AttackSets by Michael Hoffmann, CCC, November 09, 2009

2010 ...

 * Bitboards by Jeroen de Bruin, Winboard Forum, July 07, 2010
 * Low memory usage attack bitboard generation by crystalclear, Winboard Forum, October 06, 2011
 * Re: Bitboard implementation, how much time? by Michael Hoffmann, CCC, January 26, 2012
 * 152k rook and bishop attacks using PEXT and PDEP by Lasse Hansen, CCC, October 06, 2013 » BMI2

2015 ...

 * On Rook tables in magic move generation by Syed Fahad, CCC, February 22, 2015
 * Yet another way of generating sliding attack masks by Syed Fahad, CCC, March 09, 2015
 * New idea for Rook magic moves storage by Fermin Serrano, CCC, March 22, 2015
 * Slider attack mask generation without table lookup by Syed Fahad, CCC, May 24, 2015
 * Comparison of bitboard attack-getter variants by Sven Schüle, CCC, January 04, 2016
 * SBAMG - Completing Hyperbola Quintessence by Syed Fahad, CCC, April 10, 2016
 * very small bitboard move/attack generator by Vivien Clauzon, CCC, October 27, 2018

=External Links=
 * Slide attack from Wikipedia
 * Focus - Glider, Ship of Memories 1976, YouTube Video

=References=

Up one Level