Answers.Body: <p>You would use the same AND-ing of the board map and the attack bitmap to get a set of attacked positions, but you must then also cast a ray from any attacked piece back to the attacker to verify that the attack path is unobstructed.  The ray cast check could use a bitmap as well, indexed and fetched by the attacker and attackee positions, but given the heavy time penalty for memory cache misses, it's probably going to be cheaper just to check the squares along the ray path one by one.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-23T17:45:50.603Z
Answers.LastActivityDate: 2021-10-23T17:45:50.603Z
Answers.UserDisplayName: Kyle Jones
Body: <p>I have been searching about bit boards and piece attacks. The concept of using a bitwise <code>and</code> to find the set of attacked pieces (ie: <code>knightAttackSet &amp; opponentPieces</code>) is really elegant and straightforward, but I don't understand how it would work for sliding pieces : how do you efficiently detect that some pieces are hidden behind others, and thus not actually attacked? I could of course write a program doing this, but I'd like to know about the most recommended algorithms for doing this, and I can't find it easily on chess programming wiki. What are these methods? Thank you.</p>
  
Tags: <programming><bitboard>
Title: Bitboards and sliding piece attacks
ThreadText: # Bitboards and sliding piece attacks
  
  (Asked by: username_0 on 2021-10-23)
  
  I have been searching about bit boards and piece attacks. The concept of using a bitwise `and` to find the set of attacked pieces (ie: `knightAttackSet & opponentPieces`) is really elegant and straightforward, but I don't understand how it would work for sliding pieces : how do you efficiently detect that some pieces are hidden behind others, and thus not actually attacked? I could of course write a program doing this, but I'd like to know about the most recommended algorithms for doing this, and I can't find it easily on chess programming wiki. What are these methods? Thank you.
  
  **Tags:** programming, bitboard
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-10-23. Score: 1 | Accepted answer
  
  You would use the same AND-ing of the board map and the attack bitmap to get a set of attacked positions, but you must then also cast a ray from any attacked piece back to the attacker to verify that the attack path is unobstructed. The ray cast check could use a bitmap as well, indexed and fetched by the attacker and attackee positions, but given the heavy time penalty for memory cache misses, it's probably going to be cheaper just to check the squares along the ray path one by one.
  
  
  ---
  
  