0

Writing a legal move generator, I had an idea to use the same approach as bishop/rook attacks for pins (and discover checks). The idea is that, for a given occupancy, it returns the second set bit (if exists) in all 8 directions from a given square. In this approach, you cannot ignore edges with the masks because it matters whether the edge squares are populated or not.

This gives us larger tables for bishops and rooks (2^13 for bishops, 2^14 for rooks).

I have found magic numbers for most squares, but for the rest I'm stuck. I'm using the same logic as proposed here, which I'm sure you're familiar with: https://www.chessprogramming.org/Looking_for_Magics

The only change is that I don't ignore edges in the masks, and of course the array size is bigger (16384 for rooks, 8192 for bishops)

Missing squares:

  • Bishops: e4
  • Rooks: a8, g6, c5, c4, f4, g4, h4, a3, c3, f3, g3, h3

I guess I have two questions:

  • Is there a better way to find magic numbers?
  • Is it possible to tell if certain squares are not possible for a given bits count?

I would be extremely thankful to get some help with finding these missing numbers. Below the two tables modified with the correct relevant bits for my purpose.

int RBits[64] = {
    14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14
};

int BBits[64] = {
    7, 7, 7, 7, 7, 7, 7, 7,
    7, 9, 9, 9, 9, 9, 9, 7,
    7, 9, 11, 11, 11, 11, 9, 7,
    7, 9, 11, 13, 13, 11, 9, 7,
    7, 9, 11, 13, 13, 11, 9, 7,
    7, 9, 11, 11, 11, 11, 9, 7,
    7, 9, 9, 9, 9, 9, 9, 7,
    7, 7, 7, 7, 7, 7, 7, 7
};

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.