The easiest bitboard slider-attacks code to write is the standard or classical method:
http://chessprogramming.wikispaces.com/ ... l+Approach
Here's an implementation of RookAttacks().
Code: Select all
extern BitBoard gRayN[64], gRayE[64], gRayS[64], gRayW[64];
BitBoard RookAttacks( int fromSquare, BitBoard occupied )
{
int blockingSquare;
BitBoard attacks, partAttacks, blockers;
attacks = gRayN[fromSquare];
blockers = attacks & occupied;
if ( blockers )
{
blockingSquare = GetLowestBit( blockers );
attacks ^= gRayN[blockingSquare]; // mask off beyond blocking square
}
partAttacks = gRayE[fromSquare];
blockers = partAttacks & occupied;
if ( blockers )
{
blockingSquare = GetLowestBit( blockers );
partAttacks ^= gRayE[blockingSquare];
}
attacks |= partAttacks;
partAttacks = gRayS[fromSquare];
blockers = partAttacks & occupied;
if ( blockers )
{
blockingSquare = GetHighestBit( blockers );
partAttacks ^= gRayS[blockingSquare];
}
attacks |= partAttacks;
partAttacks = gRayW[fromSquare];
blockers = partAttacks & occupied;
if ( blockers )
{
blockingSquare = GetHighestBit( blockers );
partAttacks ^= gRayW[blockingSquare];
}
return attacks | partAttacks;
}
BishopAttacks() is similar, with the obvious substitutions (gRayNW[], gRayNE[], gRaySE[], gRaySW[]).
These functions are quite easy to understand, which is important while you get used to bitboard programming. They will be much faster than your existing slider-attack code, which no doubt has loops.
At some later time you may want to try magic, as a minor optimization.
Robert P.