Pinned Pieces With Bitboards

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

tcusr
Posts: 323
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: Pinned Pieces With Bitboards

Post by tcusr »

StackFish5 wrote: Fri Apr 01, 2022 4:15 am While reading an article on CPW regarding checks and pinned pieces: https://www.chessprogramming.org/Checks ... Bitboards)
I didn't fully understand this function:

Code: Select all

 pinned = 0;
pinner = xrayRookAttacks(occupiedBB, ownPieces, squareOfKing) & opRQ;
while ( pinner ) {
   int sq  = bitScanForward(pinner);
   pinned |= obstructed(sq, squareOfKing) & ownPieces;
   pinner &= pinner - 1;
}
pinner = xrayBishopAttacks(occupiedBB, ownPieces, squareOfKing) & opBQ;
while ( pinner ) {
   int sq  = bitScanForward(pinner);
   pinned |= obstructed(sq, squareOfKing) & ownPieces;
   pinner &= pinner - 1;
}

My question is what the function obstructed() does. Moreover, I would like to know whether opRQ refers to the rooks and queens. And whether opBQ refers to the bishops and queens.

Thanks.
yes opRQ contains both opposite rooks and queens, it's useful because the queen is just a rook + bishop, so you can save computation.
obstructed returns the bits between sq (the possible pinner) and squareOfKing
StackFish5
Posts: 18
Joined: Fri Dec 24, 2021 5:48 pm
Full name: Andrew Zhuo

Re: Pinned Pieces With Bitboards

Post by StackFish5 »

tcusr wrote: Fri Apr 01, 2022 3:59 pm
StackFish5 wrote: Fri Apr 01, 2022 4:15 am While reading an article on CPW regarding checks and pinned pieces: https://www.chessprogramming.org/Checks ... Bitboards)
I didn't fully understand this function:

Code: Select all

 pinned = 0;
pinner = xrayRookAttacks(occupiedBB, ownPieces, squareOfKing) & opRQ;
while ( pinner ) {
   int sq  = bitScanForward(pinner);
   pinned |= obstructed(sq, squareOfKing) & ownPieces;
   pinner &= pinner - 1;
}
pinner = xrayBishopAttacks(occupiedBB, ownPieces, squareOfKing) & opBQ;
while ( pinner ) {
   int sq  = bitScanForward(pinner);
   pinned |= obstructed(sq, squareOfKing) & ownPieces;
   pinner &= pinner - 1;
}

My question is what the function obstructed() does. Moreover, I would like to know whether opRQ refers to the rooks and queens. And whether opBQ refers to the bishops and queens.

Thanks.
yes opRQ contains both opposite rooks and queens, it's useful because the queen is just a rook + bishop, so you can save computation.
obstructed returns the bits between sq (the possible pinner) and squareOfKing
So the obstructed function is the same function as the one under Pure Calculation from https://www.chessprogramming.org/Square ... tackBySide ?
tcusr
Posts: 323
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: Pinned Pieces With Bitboards

Post by tcusr »

yes
StackFish5
Posts: 18
Joined: Fri Dec 24, 2021 5:48 pm
Full name: Andrew Zhuo

Re: Pinned Pieces With Bitboards

Post by StackFish5 »

Thank you to everyone that responded!