Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Bitboards generate moves King, Knight

Author: Gerd Isenberg

Date: 01:42:38 09/21/04

Go up one level in this thread


On September 21, 2004 at 02:05:08, Tony Werten wrote:
<snip>
>>I have different code for white and black, but I have *never* liked it. It's
>>ugly and I will eventually get rid of it.
>
>Pawn are still a problem I think, since the solution is not much nicer:
>
>( assuming the compiler understands the a negative shl is a shr )

One possible solution is using a generalized branchless shift:

http://www.azillionmonkeys.com/qed/asmexample.html

---------------------------------------------------------------------
8. Generalized shift (32-bit)

unsigned long gensh(unsigned long v, int x) {
int a, b;
    a = (v << x) & -(((unsigned int)x) < 32);
    x = -x;
    b = (v >> x) & -(((unsigned int)x) < 32);
    return a|b;
}

and asssembly
---------------------------------------------------------------------

for bitboards:

BitBoard gensh(BitBoard v, int x) {
int a, b;
    a = (v << x) & -(((unsigned int)x) < 64);
    x = -x;
    b = (v >> x) & -(((unsigned int)x) < 64);
    return a|b;
}

Another nice C++ solution for compile time constants is to use integer templates
like:

template<int color> BitBoard pushPawn (BitBoard pawns)
{
   if ( color ) return pawns >> 8;
   return pawns << 8;
}

Gerd


>
>BLACK=0
>WHITE=1
>
>int LeftSideAttack={-9,7};
>int RightSideAttack={-7,9};
>
>pieces=Pieces[stm][pawn];
>
>pawnattacks=(pieces & NOT_FILE_A)<<LeftSideAttack[stm]
>           |(pieces & NOT_FILE_H)<<RightSideAttack[stm])
>
>AttackedPieces=pawnattacks & Pieces[stm^1][all]
>
>Hmm, actually writing it down, makes it less messier than it was in my head.
>That is, if the first assumption is met.
>
>Tony
>
>
>
>
>>
>>Bas.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.