Grant Osborne wrote:Hi all
For those of you that are using Pradu's magic move bitboard generator (or understand how it works) and have a 32-bit computer,
I picked up on a recent post by H.G Muller and substituted the code above with:-
- Code: Select all
U64 Bmagic(unsigned int square) {
U64 occ = Occupied & bishopMask[square];
unsigned int lo = (int)(occ) * (int)(bishopMagic[square]);
unsigned int hi = (int)(occ >> 32) * (int)(bishopMagic[square] >> 32);
return *(bIndecies[square] + ((lo ^ hi) >> bishopShift[square]));
}
U64 Rmagic(unsigned int square) {
U64 occ = Occupied & rookMask[square];
unsigned int lo = (int)(occ) * (int)(rookMagic[square]);
unsigned int hi = (int)(occ >> 32) * (int)(rookMagic[square] >> 32);
return *(rIndecies[square] + ((lo ^ hi) >> rookShift[square]));
This modification requires a new set of two 32-bit keys per square (or like me you could join them into one 64-bit key)
Strangely my unit tests claim that your 32 bit rook multiplier for square number 27 (d4 in my numbering, which numbers a1, b1, c1 with 0,1,2) is broken. They say that the sets d2 and d2+d7 both map to the same index. Your multiplier is 0x0F4A2006C2001602. A correct multiplier is 0x0021000800001001. Number 27 is the only broken multiplier among your 128 multipliers.
Some more remarks:
1. I think you should do the encoding into a 64 bit multiplier the other way round:
- Put the multiplier that is used for the low dword of the bitboard in the high dword of the 64 bit multiplier and
- put the multiplier that is used for the high dword of the bitboard in the low dword of the 64 multiplier
This might allow to find common multipliers for 32 and 64 bit versions.
2. For aesthetical reasons I like sparse multipliers (i.e. only few bits set) better. They allow you to understand how the action on the bitboards works and can be calculated with a pencil and a sheet of paper instead of some brute force search program.
3.
and only uses two 32-bit multiplies instead of three,
Aren't even four multiplications needed? How can you compute a 64 bit product with 3 multiplications @ 32 bit?
4.
and a 32-bit shift, and is probably more suited to a 32-bit machine.
Thank you very much for the great idea!