GothicChessInventor wrote:Matthias Gemuh wrote:Given an 80-bit bitboard A, how do I code operators for "~A" and "&& A" ?
The commented lines fail.
I am not yet testing, but do you see any other errors ?
I used operator overloading and just redefined the meaning of:
&, ^, |, >>, <<, >>=, <<= etc.
You define your 80-bit item as a struct composed of a 16-bit and 64-bit portion.
Let me know if you would like to see some of the code in Gothic Vortex.
Hi Ed,
yes you can send me code snippet as private mail.
Please include ROW() and COL(), for I now use:
#define ROW(x) (((x)-((x)%10)) / 10)
#define COL(x) (x % 10)
In ArcBishop, I use this very slow, unoptimized class:
class BITBOARD {
protected:
UINT16 data16;
UINT64 data64;
public:
BITBOARD() { data16 = (UINT16)0; data64 = 0ui64; }
BITBOARD(UINT16 dat16, UINT64 dat64) { data16 = (UINT16)dat16; data64 = (UINT64)dat64; }
UINT16 GetData16() const { return((UINT16) data16); }
UINT64 GetData64() const { return((UINT64) data64); }
void PutData16(UINT16 dat16) { data16 = (UINT16)dat16; }
void PutData64(UINT64 dat64) { data64 = (UINT64)dat64; }
BITBOARD operator & (BITBOARD const BitA) const
{ return(BITBOARD(((UINT16)data16 & BitA.GetData16()), ((UINT64)data64 & BitA.GetData64()))); }
BITBOARD operator | (BITBOARD const BitA) const
{ return(BITBOARD(((UINT16)data16 | BitA.GetData16()), ((UINT64)data64 | BitA.GetData64()))); }
BITBOARD operator ^ (BITBOARD const BitA) const
{ return(BITBOARD(((UINT16)data16 ^ BitA.GetData16()), ((UINT64)data64 ^ BitA.GetData64()))); }
BITBOARD operator << (UINT16 k) const {
if (k == 0) return(*this);
else if (k <= 16) return(BITBOARD((UINT16)(((UINT64)data16 << k) | ((UINT64)data64 >> (64-k))), ((UINT64)data64 << k)));
else if (k <= 64) return(BITBOARD((UINT16)((UINT64)data64 >> (64-k)), ((UINT64)data64 << k)));
else return(BITBOARD((UINT16)((UINT64)data64 << (k-64)), ((UINT64)data64 << k)));
}
BITBOARD operator >> (UINT16 k) const {
if (k == 0) return(*this);
else if (k <= 15) return(BITBOARD(((UINT16)data16 >> k), (((UINT64)data16 << (64-k)) | ((UINT64)data64 >> k))));
else if (k <= 63) return(BITBOARD((UINT16)0, (((UINT64)data16 << (64-k)) | ((UINT64)data64 >> k))));
else return(BITBOARD((UINT16)0, ((UINT64)data16 >> (k-64))));
}
friend bool operator && (const BITBOARD& const A, const BITBOARD& const B)
{ return((A.GetData16() || A.GetData64()) && (B.GetData16() || B.GetData64())); }
friend bool operator || (const BITBOARD& const A, const BITBOARD& const B)
{ return(A.GetData16() || B.GetData16() || A.GetData64() || B.GetData64()); }
friend bool operator == (const BITBOARD& const A, const BITBOARD& const B)
{ return((A.GetData16() == B.GetData16()) && (A.GetData64() == B.GetData64())); }
friend bool operator != (const BITBOARD& const A, const BITBOARD& const B)
{ return((A.GetData16() != B.GetData16()) || (A.GetData64() != B.GetData64())); }
friend BITBOARD operator & (const UINT64 A, const BITBOARD& const B) { return(BITBOARD(0, (A & B.GetData64()))); }
friend BITBOARD operator | (const UINT64 A, const BITBOARD& const B) { return(BITBOARD(0, (A | B.GetData64()))); }
friend BITBOARD operator & (const BITBOARD& const A, const UINT64 B) { return(BITBOARD(0, (B & A.GetData64()))); }
friend BITBOARD operator | (const BITBOARD& const A, const UINT64 B) { return(BITBOARD(0, (B | A.GetData64()))); }
BITBOARD & operator = (BITBOARD const BitA)
{ data16 = (UINT16)BitA.GetData16(); data64 = (UINT64)BitA.GetData64(); return(*this); }
BITBOARD & operator = (UINT64 A) { data16 = (UINT16)0; data64 = (UINT64)A; return(*this); }
BITBOARD & operator &= (BITBOARD const BitA)
{ data16 = (UINT16)(data16 & BitA.GetData16()); data64 = (UINT64)(data64 & BitA.GetData64()); return(*this); }
BITBOARD & operator |= (BITBOARD const BitA)
{ data16 = (UINT16)(data16 | BitA.GetData16()); data64 = (UINT64)(data64 | BitA.GetData64()); return(*this); }
BITBOARD & operator ^= (BITBOARD const BitA)
{ data16 = (UINT16)(data16 ^ BitA.GetData16()); data64 = (UINT64)(data64 ^ BitA.GetData64()); return(*this); }
bool operator == (UINT64 A) { return((data16 == 0) && (data64 == A)); }
friend bool IsEmpty(BITBOARD BitA) { return((BitA.GetData16() == 0) && (BitA.GetData64() == 0ui64)); }
friend bool IsNotEmpty(BITBOARD BitA) { return((BitA.GetData16()) || (BitA.GetData64())); }
// operator bool () const { return((data64 | data16) != 0ui64); }
BITBOARD operator ~ () { return(BITBOARD((~data16), (~data64))); }
bool GetBit(int nBit) const
{
if( nBit < 64 ) return (data64 & (1ui64 << nBit)) != 0ui64;
return (data16 & (1 << (nBit - 64))) != 0;
}
void SetBit(int nBit)
{
if( nBit < 64 ) data64 = data64 | (1ui64 << nBit);
else data16 = data16 | (1 << (nBit - 64));
}
void ClearBit(int nBit)
{
if( nBit < 64 ) data64 = data64 & (0xFFFFFFFFFFFFFFFFui64 ^ (1ui64 << nBit));
else data16 = data16 & (0xFFFF ^ (1 << (nBit - 64)));
}
void ToggleBit(int nBit)
{
if( nBit < 64 ) data64 = data64 ^ (1ui64 << nBit);
else data16 = data16 ^ (1 << (nBit - 64));
}
};
Best,
Matthias.