For leapers it it works because these always have the same, shifted pattern, where some of the moves can be clipped off by the board edge. To get that same property for sliders, you would have to allow 7 moves in each of the four directions. So there would be a magic multiplier that collects a unique signature in the upper 28 bits. But that is too many bits to be useful. For sliders you must make essential use of the fact that not all their moves in opposit directions can be possible at the same time, and only collect those that are. And then omit the edge bits, corresponding to squares that cannot block moves to any other squares. But all that is dependent on the location. So you must use different multipliers for each square.
Of course for a given square you can easily construct a multiplier by hand. E.g. the attacks of a rook could be
Code: Select all
. . . . . . . .
. . . 1 . . . .
. . . 2 . . . .
. 3 4 . 5 6 7 .
. . . 8 . . . .
. . . 9 . . . .
. . . A . . . .
. . . . . . . .
You can left-shift 11 bit to get 1 and 2 in the upper ten bits, shift 34 to get 8 and 9 there, and 23 to get 3-7 there:
Code: Select all
1 . . . . . . . 2 . . . . . 3 4 . 5 6 7 . . . (<< 11)
. 8 . . . . . . . 9 . . . . . . . A . . . (<< 34)
. . 3 4 . 5 6 7 . . . . 8 . . . . . . . 9 (<< 23)
. . . . A . . . . . . . (<< 47)
_______________________________________ +
1 8 3 4 A 5 6 7 2 9 . . 8 . 3 4 ? ? 6 7
There is enough spacing between the 9 and the lower stuff that there cannot be contamination by carry, and there are no collisions. So the magic multiplier is 0x0000800400800800ull.