type

The type filter takes one argument, a set filter. It returns a number that represents the type of the piece on that square:

  x=type a1
  y=type h1
  x==y

If its argument set filter does not represent a set that has exactly one element, the type filter does not match the position. Otherwise, suppose s is the square represented by the argument set filter. The numeric values of the piece types are given by the following table:
Piece typeValue
empty0
pawn1
knight2
bishop3
rook4
queen5
king6

Examples

The type filter is used in parallelpaths.cql and babson.cql .

The babson.cql file looks for studies that are (partially) fulfill the Babson task. In the Babson task, a black pawn can promote to any of the 4 possible piece types on its next move: queen, rook, knight, bishop. Whichever piece it promotes to, white's only refutation is to promote to exactly the same piece type. For example, if Black promotes to a rook, then White's only refutation is to promote to a rook.

The file finds the following position:

Costeff 1997, after 7. Rxd1!
(found from CQL file: babson.cql)

Here, Black's natural move is 7...e:d1Q. But that fails tactically to 8. e8Q Qd4+ 9. c4!

Thus, Black might instead promote to a rook with 7...e:d1R. Here if White tries the earlier line, Black draws after 8. e8Q? Rd4+ 9. c4 Rb4+! 10. a:b4 stalemate. White prevents this idea with 8. e8R! which wins.

Finally, if Black tries 7...e:d1N then White's early ideas of 8. e8Q and 8. e8R fail to 8...N:b2#. But now 8. e8N! is White's (only) winning reply.

Thus, if Black promotes to a rook, White must promote to a rook; if Black promotes to a knight, white must promote to a knight; if Black promotes to a queen, White must promote to a queen.

In babson.cql, the Babson condition that the White and Black pawns promote to the same type is expressed by

  type pawn==Piecetype
    ...
  type Pawn==PieceType

This particular CQL file might seem a bit convoluted, since it relies on some of the more esoteric features of CQL, so we will briefly go over them.

As above, the main work is done by the function named babsonpair. This function relies on three global variables: Pawn, the particular white pawn being examined; pawn, the particular black pawn being examined, and numberbabsons, the number of Babson pairs found so far using this pawn/Pawn pair. A "Babson pair" is a pair of consecutive moves by a black and then a white pawn, each promoting to the same type.

The Babson pair condition itself is verified by the line filter. Each --> after the line keyword starts a new move, with the first --> representing the current position. So the filter after the first --> means that in the current position, the variable named pawn represents a piece that promote.

After that promotion, the filter after the second -->, namely type pawn == PieceType verifies the promotion is to the correct type. The primary here means that the next move consider should be a "primary" move - the first White response in the PGN file. This means that in a correct study it is White's only refutation. Finally, the == filter after the third --> verifies the condition for the white promotion.

This line filter is wrapped in an if statement that increments numberbabson whenever the line filter succeeds, that is, whenever there is a Babson pair for this PieceType.

Finally, the main part of the CQL file invokes babsonpair() on each possible piece type, for each pawn/Pawn pair that could be a promoting pawn (hence the piece pawn in pa-h2).

The numberbabsons>= 2 means that only positions with at least two Babson pairs are considered. The sort sorts the games in decreasing order of numberbabsons. The study here is one of only three in the Heijden database that exhibit 3 Babson pairs, that is which are "3/4 Babsons".

The Babson task is to find a position with 4 Babson pairs, that is, with numberbabsons==4. It has never been done in a study. Whether a Babson task exists in study form is the most famous open question in chess studies.