colortypefilter takes one argument, a set filter. If its argument represents a set with exactly one square, then the value of the
colortypefilter 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:
- If s is not occupied by a piece,
colortype sis 0.
- If s is occupied by a white piece, then
colortype s == type s
- If s is occupied by a black piece, then
colortype s == - type s
colortypefilter 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:
(found from CQL file: horizontallysymmetric.cql)
The relevant CQL code is this:
colortype Square == -colortype makesquare (file Square 8 - rank Square + 1)Here,
Squareis a user variable that holds a particular square. This filter will match a position if the contents of the current position at
Squareare the same as the reversed color of the contents of the position at the reflection of
Squareabout the horizontal bisector of the board.
makesquare (file Square 8 - rank Square + 1)
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
d5 are different, when
d4 the filter matches.