25,161

edits
# Changes

no edit summary

quite similar to the [[Classical Approach|Classical Approach]]. While the Classical Approach performs a [[BitScan|bitscan]], either [[BitScan#Bitscanforward|forward]] or [[BitScan#Bitscanreverse|reverse]] to determine the first blocker (if any) for the covered ray-attack [[General Setwise Operations#ExclusiveOr|exclusion]] by a ray-square lookup,

Shifted Bitboards performs a [[Fill Algorithms|fill-like]] [[General Setwise Operations#Union|union]] of all six [[General Setwise Operations#ShiftingBitboards|direction shifts]] of the blocker(s) from one to six (the maximum amount of covered squares behind a blocker), which were then [[General Setwise Operations#XorWithout|excluded]] from the initial [[On an empty Board#RayAttacks|empty board ray-wise attack set]].

<pre>

U64 rayAttacks[8][64]; // requires initialization

U64 getRightRayAttacks(U64 occupied, enumSquare square) {

U64 attacks = rayAttacks[right][square];

U64 blocker = attacks & occupied;

if ( blocker ) {

blocker = (blocker << 1) | (blocker << 2)

| (blocker << 3) | (blocker << 4)

| (blocker << 5) | (blocker << 6);

attacks ^= (blocker & attacks);

}

return attacks;

}

</pre>

=See also=