I made the correction.Probably not the last.
Code: Select all
u64 RookAttacks(u08 sq, bbu occ) {
u64 bb = ss1[sq][(occ.b64 >> ((((sq >> 3) << 3) + 1) & 63))];
occ.b64 >>= (sq & 7) & 0x0001010101010100;
bb &= ss2[sq][0][occ.b08.rank1];
bb &= ss2[sq][1][occ.b08.rank2];
bb &= ss2[sq][2][occ.b08.rank3];
bb &= ss2[sq][3][occ.b08.rank4];
bb &= ss2[sq][4][occ.b08.rank5];
bb &= ss2[sq][5][occ.b08.rank6];
return bb;
I'll just pick a square at random, 57. Okay not quite random as that was the year I was born.
[(occ.b64 >> ((((sq >> 3) << 3) + 1) & 63))]
All I want is the rank occupancy as an index. So 57 >> 3 = 7. Then 7 << 3 = 56 + 1 = 57. Hmm, not the best example to start with but I guess it works. Okay let's do square 35 the year my mom was born. 35 >> 3 = 4. Then 4 << 3 = 32 + 1 = 33. So if occ is shifted down by 33 then the blocker on 34 if there is one will be at bit zero. Then & 63 results in an index to access the ss1[sq][index] for a bb allowed by the rank blockers.
occ.b64 >>= (sq & 7) & 0x0001010101010100;
Now all we want are the file bits as an index of 0 or 1. Therefore we shift all the file bits to file1 and mask everything else away. If a bit accessed by rank is 0 then 0xffffffffffffffff is anded because it does not limit the squares that can be moved to. If the index is a 1 then the move set that bit allows is anded. When all the possible bit sets have been anded together what is left should be the rook attacks.
EDIT:
57 = 0b111001 & 0b111000 = 111000 = 56 + 1 = 57
35 = 0b100011 & 0b111000 = 100000 = 32 + 1 = 33 Okay, they both work. Let's try a couple more.
63 = 0b111111 & 0b111000 = 111000 = 56 + 1 = 57 Cool!
01 = 0b000001 & 0b111000 = 000000 = 0 + 1 = 1 !
That then simplifies the code to.
u64 bb = ss1[sq][(occ.b64 >> ((sq & 56) + 1) & 63];
Code: Select all
u64 RookAttacks(u08 sq, bbu occ) {
u64 bb = ss1[sq][occ.b64 >> ((sq & 56) + 1)];
occ.b64 >>= (sq & 7) & 0x0001010101010100;
bb &= ss2[sq][0][occ.b08.rank1];
bb &= ss2[sq][1][occ.b08.rank2];
bb &= ss2[sq][2][occ.b08.rank3];
bb &= ss2[sq][3][occ.b08.rank4];
bb &= ss2[sq][4][occ.b08.rank5];
bb &= ss2[sq][5][occ.b08.rank6];
return bb;
Does this make more sense now?