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.
1 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.