CDaley11 wrote:I've been thoroughly studying the magic bitboard technique for quite some time now and I think I am starting to understand it. My question is: When calculating all the possible occupany variations (i.e, variations of possible blockers) for a sliding piece on a specific square, does it matter what order the variations are calculated and then stored in? So long as I have all the possible variations in an array, will there always be a magic number that will work to give the right indexes in that array?
CDaley11 wrote:What I'm trying to say is, lets say that I have an attack table for a rook. Is there a certain order that these attacks have to be put in? If I took the array of all the possible attacks, and jumbled up the order, would there still be a magic number that works?
. . . . . . . .
. . . . . . 1 .
. 1 . . . 1 . .
. . 1 . 1 . . .
. . . . . . . .
. . 1 . 1 . . .
. 1 . . . 1 . .
. . . . . . . .
bool testMagic( u64 magic2try, u64 occUniverse, u32 numberOfIndexBits, u32 sq) {
u64 table[1 << maxNumberOfBits];
memset(table, 0, sizeof(table));
u64 occ = 0;
do { // for all occupancies starting with empty set
u32 index = occ * magic2try >> (64 - numberOfBits);
u64 attacks = applySomeSlowAttackGetter(sq, occ);
if ( table[index] == 0 ) {
table[index] = attacks; // no collision, store attack set
} else {
// collision
if ( table[index] != attacks ) {
return false; // magic does not work
}
}
occ = (occ - occUniverse) & occUniverse; // next occupancy
} while ( occ );
return true;
}
Another fast approach:
http://www.dcs.bbk.ac.uk/~mark/download ... _final.pdf
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 1 guest