Coding a bitboard class
Posted: 16 Sep 2007, 14:13
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 ?
class BITBOARD {
protected:
UINT16 data16;
UINT64 data64;
public:
BITBOARD() { data16 = 0; data64 = 0ui64; }
BITBOARD(UINT16 dat16, UINT64 dat64) { data16 = dat16; data64 = dat64; }
UINT16 GetData16() const { return data16; }
UINT64 GetData64() const { return data64; }
void PutData16(UINT16 dat16) { data16 = dat16; }
void PutData64(UINT64 dat64) { data64 = dat64; }
BITBOARD operator & (BITBOARD BitA) const
{ return(BITBOARD((GetData16() & BitA.GetData16()), (GetData64() & BitA.GetData64()))); }
BITBOARD operator | (BITBOARD BitA) const
{ return(BITBOARD((GetData16() | BitA.GetData16()), (GetData64() | BitA.GetData64()))); }
BITBOARD operator ^ (BITBOARD BitA) const
{ return(BITBOARD((GetData16() ^ BitA.GetData16()), (GetData64() ^ BitA.GetData64()))); }
bool operator && (BITBOARD BitA) const
{ return((GetData16() || GetData64()) && (BitA.GetData16() || BitA.GetData64())); }
bool operator || (BITBOARD BitA) const
{ return(GetData16() || BitA.GetData16() || GetData64() || BitA.GetData64()); }
bool operator == (BITBOARD BitA) const
{ return((GetData16() == BitA.GetData16()) && (GetData64() == BitA.GetData64())); }
bool operator != (BITBOARD BitA) const
{ return((GetData16() != BitA.GetData16()) || (GetData64() != BitA.GetData64())); }
BITBOARD & operator = (BITBOARD BitA)
{ PutData16(BitA.GetData16()); PutData64(BitA.GetData64()); return(*this); }
BITBOARD & operator &= (BITBOARD BitA)
{ PutData16(GetData16() & BitA.GetData16()); PutData64(GetData64() & BitA.GetData64()); return(*this); }
BITBOARD & operator |= (BITBOARD BitA)
{ PutData16(GetData16() | BitA.GetData16()); PutData64(GetData64() | BitA.GetData64()); return(*this); }
BITBOARD & operator ^= (BITBOARD BitA)
{ PutData16(GetData16() ^ BitA.GetData16()); PutData64(GetData64() ^ BitA.GetData64()); return(*this); }
// BITBOARD operator ~ (*this) { return(BITBOARD((~GetData16()), (~GetData64()))); }
// bool operator && (*this) { return((GetData16()) || (GetData64())); }
};
The commented lines fail.
I am not yet testing, but do you see any other errors ?
class BITBOARD {
protected:
UINT16 data16;
UINT64 data64;
public:
BITBOARD() { data16 = 0; data64 = 0ui64; }
BITBOARD(UINT16 dat16, UINT64 dat64) { data16 = dat16; data64 = dat64; }
UINT16 GetData16() const { return data16; }
UINT64 GetData64() const { return data64; }
void PutData16(UINT16 dat16) { data16 = dat16; }
void PutData64(UINT64 dat64) { data64 = dat64; }
BITBOARD operator & (BITBOARD BitA) const
{ return(BITBOARD((GetData16() & BitA.GetData16()), (GetData64() & BitA.GetData64()))); }
BITBOARD operator | (BITBOARD BitA) const
{ return(BITBOARD((GetData16() | BitA.GetData16()), (GetData64() | BitA.GetData64()))); }
BITBOARD operator ^ (BITBOARD BitA) const
{ return(BITBOARD((GetData16() ^ BitA.GetData16()), (GetData64() ^ BitA.GetData64()))); }
bool operator && (BITBOARD BitA) const
{ return((GetData16() || GetData64()) && (BitA.GetData16() || BitA.GetData64())); }
bool operator || (BITBOARD BitA) const
{ return(GetData16() || BitA.GetData16() || GetData64() || BitA.GetData64()); }
bool operator == (BITBOARD BitA) const
{ return((GetData16() == BitA.GetData16()) && (GetData64() == BitA.GetData64())); }
bool operator != (BITBOARD BitA) const
{ return((GetData16() != BitA.GetData16()) || (GetData64() != BitA.GetData64())); }
BITBOARD & operator = (BITBOARD BitA)
{ PutData16(BitA.GetData16()); PutData64(BitA.GetData64()); return(*this); }
BITBOARD & operator &= (BITBOARD BitA)
{ PutData16(GetData16() & BitA.GetData16()); PutData64(GetData64() & BitA.GetData64()); return(*this); }
BITBOARD & operator |= (BITBOARD BitA)
{ PutData16(GetData16() | BitA.GetData16()); PutData64(GetData64() | BitA.GetData64()); return(*this); }
BITBOARD & operator ^= (BITBOARD BitA)
{ PutData16(GetData16() ^ BitA.GetData16()); PutData64(GetData64() ^ BitA.GetData64()); return(*this); }
// BITBOARD operator ~ (*this) { return(BITBOARD((~GetData16()), (~GetData64()))); }
// bool operator && (*this) { return((GetData16()) || (GetData64())); }
};