## Bitboard implementation, how much time?

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Posts: 638
Joined: Mon Dec 15, 2008 10:45 am

### Re: Bitboard implementation, how much time?

Hi, Ed,

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&#40;sq_t sq,bb_t occ&#41;
&#123;
bb_t tmp,att=0;

tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bHF | bR8&#41;) == 0&#41; &#123;att |= tmp <<= 9;&#125;
tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bAF | bR8&#41;) == 0&#41; &#123;att |= tmp <<= 7;&#125;
tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bAF | bR1&#41;) == 0&#41; &#123;att |= tmp >>= 9;&#125;
tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bHF | bR1&#41;) == 0&#41; &#123;att |= tmp >>= 7;&#125;

return&#40;att&#41;;
&#125;

static bb_t generateR&#40;sq_t sq,bb_t occ&#41;
&#123;
bb_t tmp,att=0;

tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bHF&#41;) == 0&#41; &#123;att |= tmp <<= 1;&#125;
tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bAF&#41;) == 0&#41; &#123;att |= tmp >>= 1;&#125;
tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bR8&#41;) == 0&#41; &#123;att |= tmp <<= 8;&#125;
tmp = onebit&#40;sq&#41;;while&#40;&#40;tmp & &#40;occ | bR1&#41;) == 0&#41; &#123;att |= tmp >>= 8;&#125;

return&#40;att&#41;;
&#125;
``````