colortype

The colortype filter takes one argument, a set filter. If its argument represents a set with exactly one square, then the value of the colortype filter is a number that represents the color and type of the piece on that square:

  x=colortype a1
  y=colortype h1
  x==y

If the argument set filter does not represent a set that has exactly one element, the colortype filter does not match the position.

Otherwise, suppose s is the square represented by the argument set filter. Then:

  1. If s is not occupied by a piece, colortype s is 0.
  2. If s is occupied by a white piece, then
    colortype s == type s 
  3. If s is occupied by a black piece, then
    colortype s == - type s 

Examples

The colortype filter is used in chameleon.cql, flipverticalecho.cql, and horizontallysymmetric.cql . Its use in chameleon.cql is discussed in the documentation for the : operator.

Let's consider the use of colortype in the file horizontallysymmetric.cql, where it is used to find positions that look the same when the players switch sides, like the following from a Korolkov study:

Korolkov 1972
(found from CQL file: horizontallysymmetric.cql)

The relevant CQL code is this:

 colortype Square ==
     -colortype
         makesquare (file Square
	             8 - rank Square + 1)
Here, Square is a user variable that holds a particular square. This filter will match a position if the contents of the current position at Square are the same as the reversed color of the contents of the position at the reflection of Square about the horizontal bisector of the board.

In particular,

         makesquare (file Square
	             8 - rank Square + 1)

represents the reflected Square (see the documentation for makesquare, file, and rank to see why). For example, if Square is d4 then this expression will have value of d5.

Now, the colortype filters just compare the color and types of the contents of these two squares. The second colortype is negated, which inverts its color (and has no change to an empty square).

In the position above, since the d5 is the reflected version of d4, and since the color of the Kings on d4 and d5 are different, when Square is d4 the filter matches.