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.
User avatar
Desperado
Posts: 638
Joined: Mon Dec 15, 2008 10:45 am

Re: Bitboard implementation, how much time?

Post by Desperado » Thu Jan 26, 2012 8:59 am

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(sq_t sq,bb_t occ)
{
    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;
_Until_ your engine is ready for a _real_ attackGetter,
these 2 little functions will do the work you need.

NO HEADACHE :lol:

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

Post Reply