I am new user, joining here in desperate hope that this community can help me solve the problem I face.
I am trying to create a bitboard that represents the path between :
1.) sliding piece giving check to the king (not included in the path)
2.) king itself (included in the path)
3.) square behind king.
In below diagram, bitboard should have squares e3, e4, e5, e6, and e7 set:
[d]8/8/4k3/8/8/8/4R3/8 w - - 0 1
I am using Golang to code the chess engine. Bitboards use Little-Endian Rank-File Mapping. Slider attacks are calculated with magic bitboards, while knight, king and pawn attacks are precomputed. Below is the code that produces almost correct path, square behind king is missing:
Code: Select all
attacker := int(bitboard.ToSquare("e2"))
king := int(bitboard.ToSquare("e6"))
attackerBB := rook.RookAttacks(attacker, 1<<king) // RookAttack(square, occupancy) returns attack mask using magic bitboards
kingBB := rook.RookAttacks(king, 1<<attacker)
checkmask := kingBB&attackerBB | (1 << king)
One idea that came to my mind was to use precomputed attack mask for the king, for the square king stands on, and somehow cut off all the squares aside from one behind him. Then I could simply OR the square behind him into the existing path.
I apologize if I am sounding confusing, this is my first time posting here, and asking for an advice regarding chess programming.
If you need further info, or you have any questions, feel free to reach out. Thank you.