With help from Gerd, a lot of head banging (my own) and very little sleep
this is what I have arrived at. So, Gerd if you are still here, please
take one more look at this before I start testing. Thanks! No big hurry,
I will be sleeping for a couple of days.
I am very interested in magic, especially for the rooks, however I want
to get this pure shifting method up and running first before I try something
that I do not understand very well yet.
Note: Because, the queen uses both calls, occ is only the blockers
when these routines are called.
- Code: Select all
u64 Bishop32Attacks(u64 *occ, square *sq) {
sq-> index = occ-> lo | (occ-> hi >> 1);
sq-> index |= (sq-> index >> sq-> bishop-> shifts);
sq-> LoMPI = bishopLoMinimalPerfectIndex[ sq -> index & 0xff];
sq-> HiMPI = bishopHiMinimalPerfectIndex[(sq -> index >> 8) & 0xff];
return bishopAttacks[sq-> bOff + (sq->LoMPI | sq-> HiMPI)];
}
u64 Bishop64Attacks(u64 *occ, square *sq) {
sq-> index = occ-> lo | (occ-> hi >> 1);
sq-> index |= (sq-> index >> sq-> bishop-> shifts);
return loBishopAttacks[sq-> loBAOff + sq-> index & 0xff];
& hiBishopAttacks[sq-> hiBAOff + (sq-> index >> 8) & 0xff];
}
u64 Rook32Attacks(u64 *occ, square *sq) {
sq-> index = rankIndexs[(u32)(*occ & sq-> rank) >> sq-> rook-> raShift]
| ((occ-> lo & sq-> rook-> loMask1) >> sq-> rook-> loShift)
| ((occ-> hi & sq-> rook-> hiMask1) >> sq-> rook-> hiShift);
sq-> index |= ((index & sq-> rook-> loMask2) >> sq-> rook-> shift34);
sq-> LoMPI = rookLoMinimalPerfectIndex[ sq -> index & 0xff];
sq-> HiMPI = rookHiMinimalPerfectIndex[(sq -> index >> 8) & 0xff];
return rookAttacks[sq-> rOff + (sq-> LoMPI | sq-> HiMPI)];
}
u64 Rook64Attacks(u64 *occ, square *sq) {
sq-> index = rankIndexs[(u32)(*occ & sq-> rank) >> sq-> rook-> raShift]
| ((occ-> lo & sq-> rook-> loMask1) >> sq-> rook-> loShift)
| ((occ-> hi & sq-> rook-> hiMask1) >> sq-> rook-> hiShift);
sq-> index |= ((index & sq-> rook-> loMask2) >> sq-> rook-> shift34);
return loRookAttacks[sq-> loRAOff + sq-> index & 0xff]
& hiRookAttacks[sq-> hiRAOff + (sq ->index >> 8) & 0xff];
}
Edit:
Note: The below mappings are not 100%. The idea is that the rank
bits can be placed into the first 16 bits exactly how they are needed
so that the other bits can be packed in to form two split minimal indexs.
End edit
The new idea for the rooks is to retrieve a rank index that looks like this:
For an a-file or h-file square:
x x x . . . . .
x x x . . . . .
or
x x . . . . . .
x x x x . . . .
or
x x x x . . . .
x x . . . . . .
depending on the other shift patterns.
For any other square:
x x . . . . . .
x x x . . . . .
or
x x x . . . . .
x x . . . . . .
depending on the other shift patterns.
This allows perfectly compressed split indexs for the rooks
Mike