if you really like a simple (not to say trivial) approach for start up
and to make your engine ready for bitboards, here is my proposal.
It is complete direct computation, no lookups, short, pretty safe and
absolutely not fragil for ugly bugs.
Code: Select all
static bb_t generateB(sq_t sq,bb_t occ)
{
bb_t tmp,att=0;
tmp = onebit(sq);while((tmp & (occ | bHF | bR8)) == 0) {att |= tmp <<= 9;}
tmp = onebit(sq);while((tmp & (occ | bAF | bR8)) == 0) {att |= tmp <<= 7;}
tmp = onebit(sq);while((tmp & (occ | bAF | bR1)) == 0) {att |= tmp >>= 9;}
tmp = onebit(sq);while((tmp & (occ | bHF | bR1)) == 0) {att |= tmp >>= 7;}
return(att);
}
static bb_t generateR(sq_t sq,bb_t occ)
{
bb_t tmp,att=0;
tmp = onebit(sq);while((tmp & (occ | bHF)) == 0) {att |= tmp <<= 1;}
tmp = onebit(sq);while((tmp & (occ | bAF)) == 0) {att |= tmp >>= 1;}
tmp = onebit(sq);while((tmp & (occ | bR8)) == 0) {att |= tmp <<= 8;}
tmp = onebit(sq);while((tmp & (occ | bR1)) == 0) {att |= tmp >>= 8;}
return(att);
}
these 2 little functions will do the work you need.
NO HEADACHE
Finally for my personal taste, and if you never heard of
Obstruction Difference, you should risk a look at it when the time has
come.
Best regards,
Michael