Skip to content

Instantly share code, notes, and snippets.

@Ravenslofty
Created December 22, 2016 14:50
Show Gist options
  • Save Ravenslofty/93b6376fa59a1517c2d74e036ef06906 to your computer and use it in GitHub Desktop.
Save Ravenslofty/93b6376fa59a1517c2d74e036ef06906 to your computer and use it in GitHub Desktop.
Mailbox bitlist generator
const char Vector[5][8] = {
{ +10, +11, +1, -9, -10, -11, -1, +9 }, // K
{ +10, +11, +1, -9, -10, -11, -1, +9 }, // Q
{ +10, +1, -10, -1, 0, 0, 0, 0 }, // R
{ +11, -9, -11, +9, 0, 0, 0, 0 }, // B
{ +21, +12, -8, -19, -21, -12, +8, +19 } // N
};
const char Slide[5] = {
0, 1, 1, 1, 0
};
void GenBitlistMailbox(struct Board * b, int tmp, int from, int piece)
{
int dir = 0;
while (dir < 8) {
int inc = Vector[piece][dir];
int dest = ToMailbox[from] + inc;
int dest64 = FromMailbox[dest];
if (!inc) break;
while (dest64 != INVALID) {
b->bitlist[dest64] ^= tmp;
if (b->index[dest64] != INVALID || !Slide[piece])
break;
dest += inc;
dest64 = FromMailbox[dest];
}
dir++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment