http://chessprogramming.wikispaces.com/ ... tackBySide
where i found this...
Code: Select all
Pure Calculation
A branch-less solution without any lookups and some parallel gain is likely too expensive on the fly and may at most used for initialization purposes:
U64 obstructed(enumSquare sq1, enumSquare sq2)
{
const U64 m1 = C64(-1);
const U64 a2a7 = C64(0x0001010101010100);
const U64 b2g7 = C64(0x0040201008040200);
const U64 g2b7 = C64(0x0002040810204000);
U64 btwn, line, rank, file;
btwn = (m1 << sq1) ^ (m1 << sq2);
file = (sq2 & 7) - (sq1 & 7);
rank = ((sq2 | 7) - sq1) >> 3 ;
line = ( (file & 0xff) - 1) & a2a7; // a2a7 if same file
line += 2 * (( (rank & 0xff) - 1) >> 58); // b1g1 if same rank
line += (((rank - file) & 0xff) - 1) & b2g7; // b2g7 if same diagonal
line += (((rank + file) & 0xff) - 1) & g2b7; // g2b7 if same antidiag
return (line * (btwn & -btwn)) & btwn; // mul acts like shift by smaller square
}
which i think, can much easier be handled with the _idea_ of
obstrutionDifference
Code: Select all
UI_64 obstructed(UI_64 lineMask,SQR_T loSq,SQR_T hiSq)
{
UI_64 lo = (UI_64) 1 << loSq;
UI_64 hi = (UI_64) 1 << hiSq;
return(lineMask & (hi-2*lo));
}
if something is wrong with this, let me know (only tested for some examples).
i further think this is a very fast on the fly solution, with no memory
issues to think about, because file,rank,diag,anti masks are given
anyway in bitboard progs.
Michael