Knight Pattern
with Bitboards covers knightattacks of single or multiple knights, either by indexed pre-calculated tables or direct bitboard calculation, and the set wise determination of Knight fork target squares.

The Knight attacks the target squares independently from other pieces around. The compass rose of all eight attacking directions associated with the to - from square differences from an 8x8 board:

Similar to one step only of the four orthogonal and four diagonal directions,each of the eight knight directions is calculated by left or right shift with appropriate pre- or post shift mask, to avoid A- H-file wraps or vice versa. See also AVX2 Knight Attacks.

In almost the same manner as the three pawn directions, there is a unique source-target relationship. The difference is - we have up to eight pawns, but likely not more than two knights per side. Keeping eight disjoint knight directions is consistent to direction-wise fill approaches of other pieces with unique target-source relationship - but disjoint direction-wise knight targets are sparse populated and usually contain only up to two bits.

Multiple Knight Attacks

To initialize the KnightAttacks array one may use a routine with some kind of parallel prefix calculations, rather than the union of all eight directions:

U64 knightAttacks(U64 knights){
U64 west, east, attacks;
east = eastOne (knights);
west = westOne (knights);
attacks =(east|west)<<16;
attacks |=(east|west)>>16;
east = eastOne (east);
west = westOne (west);
attacks |=(east|west)<<8;
attacks |=(east|west)>>8;return attacks;}

If we pass multiple knights set-wise, attacks of some squares may be caused by different knights. Feeding back (safe) target sets, the routine may used to get sets of squares, knights may reach in two or more moves. For instance in late pawn-knight endings whether a knight may catch a passer.

Knight Fill

A fill cycle for a fill algorithm is the union of the attack set with the knights itself:

A common knight pattern is the knight fork. Targets are heavy pieces - king, queen and rooks, hanging pieces, or even undefended pawns. A royal knight fork or "family" check, winning the queen is most important. Otherwise one may loop over all possible pieces, to get the knight-attacks by lookup and to intersect all combinations of attack-squares. A loop- and branch-less solution to get potential fork-attack squares is to union all intersections of all direction attacks, as explained in greater one sets:

U64 forkTargetSquare(U64 targets){
U64 west, east, attak, forks;
east = eastOne (targets);
west = westOne (targets);
attak = east <<16;
forks =(west <<16)& attak;
attak |= west <<16;
forks |=(east >>16)& attak;
attak |= east >>16;
forks |=(west >>16)& attak;
attak |= west >>16;
east = eastOne (east);
west = westOne (west);
forks |=(east <<8)& attak;
attak |= east <<8;
forks |=(west <<8)& attak;
attak |= west <<8;
forks |=(east >>8)& attak;
attak |= east >>8;
forks |=(west >>8)& attak;return forks;}

The intersection of those targets with squares not occupied by own pieces or attacked by opponent pawns and knights, but attacked by own knight(s) leaves a move target set with some forced properties.

Home * Board Representation * Bitboards * Knight PatternKnight Patternwith Bitboards covers knight attacks of single or multiple knights, either by indexed pre-calculated tables or direct bitboard calculation, and the set wise determination of Knight fork target squares.

^{[1]}## Table of Contents

## Knight Attacks

The Knight attacks the target squares independently from other pieces around. The compass rose of all eight attacking directions associated with the to - from square differences from an 8x8 board:## by Lookup

The knight is specified by square index, likely from a bitscan of a piece-wise bitboard serialization of a knight bitboard from a standard board-definition, to index a table of pre-calculated knight-attacks:For instance a knight on d4

## by Calculation

Similar to one step only of the four orthogonal and four diagonal directions,each of the eight knight directions is calculated by left or right shift with appropriate pre- or post shift mask, to avoid A- H-file wraps or vice versa. See also AVX2 Knight Attacks.In almost the same manner as the three pawn directions, there is a unique source-target relationship. The difference is - we have up to eight pawns, but likely not more than two knights per side. Keeping eight disjoint knight directions is consistent to direction-wise fill approaches of other pieces with unique target-source relationship - but disjoint direction-wise knight targets are sparse populated and usually contain only up to two bits.

## Multiple Knight Attacks

To initialize the KnightAttacks array one may use a routine with some kind of parallel prefix calculations, rather than the union of all eight directions:or to possibly gain some more parallelism:

If we pass multiple knights set-wise, attacks of some squares may be caused by different knights. Feeding back (safe) target sets, the routine may used to get sets of squares, knights may reach in two or more moves. For instance in late pawn-knight endings whether a knight may catch a passer.

## Knight Fill

A fill cycle for a fill algorithm is the union of the attack set with the knights itself:for instance applied six times on the otherwise empty board:

## Knight Forks

A common knight pattern is the knight fork. Targets are heavy pieces - king, queen and rooks, hanging pieces, or even undefended pawns. A royal knight fork or "family" check, winning the queen is most important. Otherwise one may loop over all possible pieces, to get the knight-attacks by lookup and to intersect all combinations of attack-squares. A loop- and branch-less solution to get potential fork-attack squares is to union all intersections of all direction attacks, as explained in greater one sets:The intersection of those targets with squares not occupied by own pieces or attacked by opponent pawns and knights, but attacked by own knight(s) leaves a move target set with some forced properties.

## See also

## Selected Publications

1967).Problems that are Built on the Knight's Tour in Chess. Scientific American, Vol. 1302003).The Mathematical Knight. The Mathematical Intelligencer, Vol. 25, No. 1, pdf2004).Knight’s Tours. pdf2005).Ant Colonies Discover Knight's Tours. AI 2004, Lecture Notes in Computer Science 33392005).Enumerating knight's tours using an ant colony algorithm. CEC 2005## Forum Posts

## External Links

## References

## What links here?

Up one Level