### A Combination

Posted:

**Sun Apr 19, 2015 11:54 am**Hi

I put up a post a few years ago about using magics to get a bitboard of pinned pieces, and the general concensus was that it was not worth the computational effort and extra lookups to get this information, as pinned pieces are rare.

However, since we all have to determine whether or not we are in check, with only a little extra effort (and lookup) I can combine am-I-in-check with pinned pieces:-

Both rookPinInfo and bishopPinInfo contain the following:-

If (...PinInfo & 7) is zero then not-in-check, else is the distance to the checking piece and ((...PinInfo >> 3) & 7) is the direction from the king to the checking piece.

If (...PinInfo & 0x3FFFFFC0) is zero then no-pinned-pieces, else provides distance and direction of pinned pieces AND the pinners for all 8 directions.

There are the extra 64-bit multiplys and the 286K lookup table, but if you only generate legal moves then this could possibly be an improvement. This will only work with 64-bit multiplication.

Grant

I put up a post a few years ago about using magics to get a bitboard of pinned pieces, and the general concensus was that it was not worth the computational effort and extra lookups to get this information, as pinned pieces are rare.

However, since we all have to determine whether or not we are in check, with only a little extra effort (and lookup) I can combine am-I-in-check with pinned pieces:-

Code: Select all

```
U64 attacks = RookMagic(kingSquare, RksQns(them) & allOccupied;
int rankOccupation = (attacks >> (kingSquare & 0x38)) & 0xFF;
U64 fileOccupation = (attacks >> (kingSquare & 7)) & 0x0101010101010101;
int rookPinInfo = RankPinMagic(kingSquare & 7, rankOccupation) | FilePinMagic(kingSquare >> 3, fileOccupation);
attacks = BishopMagic(kingSquare, BpsQns(them)) & allOccupied;
int bishopPinInfo = BishopPinMagic(kingSquare, attacks);
```

If (...PinInfo & 7) is zero then not-in-check, else is the distance to the checking piece and ((...PinInfo >> 3) & 7) is the direction from the king to the checking piece.

If (...PinInfo & 0x3FFFFFC0) is zero then no-pinned-pieces, else provides distance and direction of pinned pieces AND the pinners for all 8 directions.

There are the extra 64-bit multiplys and the 286K lookup table, but if you only generate legal moves then this could possibly be an improvement. This will only work with 64-bit multiplication.

Grant