Double and Triple (Bitboards)

From Chessprogramming wiki
Jump to: navigation, search

Home * Board Representation * Bitboards * Pawn Pattern and Properties * Double and Triple

Double and Triple pawns may be determined in the square centric world as well in set-wise world of Bitboards considering the whole board.

By Square

Working in the square centric world of the board implies using a square index of one particular pawn, likely from bitboard traversal. For doubled (twins) or multiple pawns on a file, we simply intersect the file-mask by own-pawns and perform a population count. This symmetrical property appears to be equal for white and black pawns, except for the before- and behind semantic.

wPawnsOnFile = arrFiles[sqOfWhitePawn] & pawnBB[white];
if ( wPawnsOnFile & (wPawnsOnFile-1) ) -> white pawn is a least double pawn
if ( wPawnsOnFile & arrNortRay[sqOfWhitePawns] ) -> white pawn has own pawn ahead
if ( wPawnsOnFile & arrSoutRay[sqOfWhitePawns] ) -> white pawn has own pawn behind
arrFiles[d*]
. . . 1 . . . .
. . . 1 . . . .
. . . 1 . . . .
. . . 1 . . . .
. . . 1 . . . .
. . . 1 . . . .
. . . 1 . . . .
. . . 1 . . . .

The arrFiles might be condensed to eight bitboards only, instead of 64 - if we index by

file(sq) == sq & 7

instead of square.

Multiple Pawns

Working in the bitboard centric world to determine pawn related pattern set-wise.

All pawns that are member of the rearspan of all own pawns, have at least one pawn in front on the same file. All pawns that are member of the frontspan of all own pawns, have at least one pawn behind on the same file.

// pawns with at least one pawn in front on the same file
U64 wPawnsBehindOwn(U64 wpawns) {return wpawns & wRearSpans(wpawns);}

// pawns with at least one pawn behind on the same file
U64 wPawnsInfrontOwn (U64 wpawns) {return wpawns & wFrontSpans(wpawns);}

Obviously, since each pawn in front of a pawn implies this pawn behind, the number of pawns in front is equal the number of pawns behind.

popCount(wPawnsBehindOwn) == popCount(wPawnsInfrontOwn)

The intersection of both sets implies at least a triple, thus a pawn in front and behind.

U64 wPawnsInfrontAndBehindOwn (U64 wpawns) {
   return wPawnsInfrontOwn(wpawns) &  wPawnsBehindOwn(wpawns);
}

If the intersection is empty on a file, it is a double pawn or a twin.

fileWithAtLeastTriple = fileFill(infrontAndBehindOwn);
rearTwin  = behindOwn  & ~fileWithAtLeastTriple;
frontTwin = infrontOwn & ~fileWithAtLeastTriple;

Forum Posts

External Links