Pradu wrote:The method used by most people is to try random numbers and it works well for generating the magics. So what you have to do is just try random numbers and one of them will end up working. I don't have a 10x8 bitboard backend yet and I'm not quite sure how it is setup for 10x8 so you could probably do it easier than I could.

The backend you mean is surely this class.

Its objects simply function like unsigned 80-bit integers :

class BITBOARD {

protected:

UINT32 data16;

UINT64 data64;

public:

//

BITBOARD(UINT32 dat16 = 0UL, UINT64 dat64 = 0ui64) {

data16 = (0x0000FFFFUL & dat16); data64 = dat64;

}

BITBOARD(const BITBOARD &BitA) { data16 = BitA.GetData16(); data64 = BitA.GetData64(); }

//

BITBOARD EmptyBitBoard() { return BITBOARD(); }

BITBOARD FullBitBoard() { return BITBOARD(0xFFFFFFFFUL, 0xFFFFFFFFFFFFFFFFui64); }

BITBOARD BitBitBoard( int nBit ) {

if (nBit <= 63) return BITBOARD(0UL, 1ui64 << nBit);

return BITBOARD((UINT32)(1ui64 << (nBit - 64)), 0ui64 );

}

//

inline UINT32 GetData16() const { return(0x0000FFFFUL & data16); }

inline UINT64 GetData64() const { return(data64); }

inline void PutData16(UINT32 dat16) { data16 = (0x0000FFFFUL & dat16); }

inline void PutData64(UINT64 dat64) { data64 = dat64; }

inline void Clear() { data16 = 0UL; data64 = 0ui64; }

//

BITBOARD operator & (const BITBOARD &BitA) const

{ return(BITBOARD((data16 & BitA.GetData16()), (data64 & BitA.GetData64()))); }

BITBOARD operator | (const BITBOARD &BitA) const

{ return(BITBOARD((data16 | BitA.GetData16()), (data64 | BitA.GetData64()))); }

BITBOARD operator ^ (const BITBOARD &BitA) const

{ return(BITBOARD((data16 ^ BitA.GetData16()), (data64 ^ BitA.GetData64()))); }

//

BITBOARD operator << (UINT32 k) const {

if (k == 0) return(*this);

if (k <= 15) return(BITBOARD(((data16 << k) | ((UINT32)(data64 >> (64-k)))), (data64 << k)));

else if (k <= 63) return(BITBOARD((UINT32)(data64 >> (64-k)), (data64 << k)));

else return(BITBOARD((UINT32)(data64 << (k-64)), 0ui64));

}

BITBOARD operator >> (UINT32 k) const {

if (k == 0) return(*this);

if (k <= 15) return(BITBOARD((UINT32)(data16 >> k), (((UINT64)data16 << (64-k)) | (data64 >> k))));

else if (k <= 63) return(BITBOARD(0UL, (((UINT64)data16 << (64-k)) | (data64 >> k))));

else return(BITBOARD(0UL, ((UINT64)data16 >> (k-64))));

}

//

bool operator && (const BITBOARD &B) const { return((data16 || data64) && (B.GetData16() || B.GetData64())); }

bool operator && (const bool A) const { return((data16 || data64) && A); }

bool operator || (const BITBOARD &B) const { return(data16 || B.GetData16() || data64 || B.GetData64()); }

bool operator || (const bool A) const { return(data16 ||data64 || A); }

bool operator != (const BITBOARD &B) const { return((data16 != B.GetData16()) || (data64 != B.GetData64())); }

bool operator != (const UINT64 A) const { return((data16 != 0ui64) || (data64 != A)); }

bool operator == (const BITBOARD &B) const { return((data16 == B.GetData16()) && (data64 == B.GetData64())); }

bool operator == (const UINT64 A) const { return((data16 == 0UL) && (data64 == A)); }

//

friend bool operator && (const bool A, const BITBOARD &B) { return(B && A); }

friend bool operator || (const bool A, const BITBOARD &B) { return(B || A); }

friend bool operator != (const UINT64 A, const BITBOARD &B) { return(B != A); }

friend bool operator == (const UINT64 A, const BITBOARD &B) { return(B == A); }

//

BITBOARD & operator = (const BITBOARD &BitA)

{ data16 = BitA.GetData16(); data64 = BitA.GetData64(); return(*this); }

BITBOARD & operator = (UINT64 A) { data16 = 0UL; data64 = A; return(*this); }

BITBOARD operator &= (const BITBOARD &BitA)

{ data16 &= BitA.GetData16(); data64 &= BitA.GetData64(); return(*this); }

BITBOARD operator |= (const BITBOARD &BitA)

{ data16 |= BitA.GetData16(); data64 |= BitA.GetData64(); return(*this); }

BITBOARD operator ^= (const BITBOARD &BitA)

{ data16 ^= BitA.GetData16(); data64 ^= BitA.GetData64(); return(*this); }

// BITBOARD & operator >>= (UINT32 k) { return(*this); }

// BITBOARD & operator <<= (UINT32 k) { return(*this); }

//

friend bool IsEmpty(const BITBOARD &BitA) { return((BitA.GetData16() | BitA.GetData64()) == 0ui64); }

friend bool IsNotEmpty(const BITBOARD &BitA) { return((BitA.GetData16()) || (BitA.GetData64())); }

bool operator ! () const { return((data64 | (UINT64)data16) == 0ui64); }

operator bool () const { return((data64 | (UINT64)data16) != 0ui64); }

BITBOARD operator ~ () { return(BITBOARD((~data16), (~data64))); }

//

bool BitIsSet(int nBit) const {

if (nBit <= 63) return (data64 & (1ui64 << nBit)) != 0ui64;

return (data16 & (1ui64 << (nBit - 64))) != 0UL;

}

void SetBit(int nBit) {

if (nBit <= 63) data64 = (data64 | (1ui64 << nBit));

else data16 = (data16 | (1ui64 << (nBit - 64)));

}

void ClearBit(int nBit) {

if (nBit <= 63) data64 = (data64 & (0xFFFFFFFFFFFFFFFFui64 ^ (1ui64 << nBit)));

else data16 = (data16 & (0xFFFF ^ (1ui64 << (nBit - 64))));

}

void ToggleBit(int nBit) {

if (nBit <= 63) data64 = (data64 ^ (1ui64 << nBit));

else data16 = (data16 ^ (1ui64 << (nBit - 64)));

}

};

If nobody can help with the magics generation, then I must understand enough of those collision algorithms to progam/modify them

Matthias.