Because all positions have to be checked, this takes a lot of time. So I am looking for a simple way to 'filter out' positions that can't possibly be mate because they have a King move to a safe square. So I am looking for an algorithm to identify all squares than border on all sides (in 8-neighbor topology) on covered squares (or squares that are occupied by own pieces). The square itself does not have to be covered, for I want to find stalemate candidates too.
The EGTB builder runs through all positions with all pieces on the board except black King, and from each such partial position it then generates 64 complete positions by adding the black King on any of the 64 squares. (Some of these are impossible, because the squares are already occupied, but there is spaced reserved for those in the TB anyway, to make the mapping from board position to TB index trivial.)
Rather than going through all these 64 positions, running the move generator for black to see if he has moves to safe squares, I would like to use some parallel algorithm to decide this (for King-moves only) for all 64-positions simultaneously. I could for instance make a bitboard with all white attacks from the partial position, orred with all black (non-King) pieces, thus marking all the squares where a black King could not go to. Now from that bitboard c, I would make the squares where a King is 'trapped'.
What is the quickest way to compute this? I can think off
- Code: Select all
a = c>>1 & ~0x8080808080808080LL | c<<1 & 0x0101010101010101LL;
b = a | c;
c = ~(a | b>>8 | b<<8);
That way I would do it with 4 OR operations, rather than the expected 8. Can it be done with less?