rookleapcorners.cqlThe CQL file rookleapcorners.cql finds a position that starts a rook leap corners theme. In this theme, a rook begins on a first corner, then moves to a second corner, then moves to a third corner, and finally moves to the fourth corner. There can be moves by any number of other white and black pieces in between those rook moves, but the thematic rook cannot make other moves during the theme.
As an example, consider the position before White's 6'th move in this Kasparyan study:
(found from CQL file: rookleapcorners.cql)
The white rook on
a8 moves according to the arrows:
9. ♖a. Note that another white piece (a
♙) makes a move between the last two rook moves.
The main distinguishing feature of this theme is that we are interested in the path taken by a single piece, a particular
♖. Moves by other pieces are not important to the theme. When this pattern arise, we can use a tool called ◎, which is a parameter to ⊢.
rookleapcorners.cql line by lineIt's tempting to start with a path like we did for greekgift.cql:
⊢ ♖a8――h8 ♖h8――h1 ♖h1――a1This won't work for three distinct reasons:
⊢as written matches successive moves. It would never match anything because after the first rook move, the game would have a black move, but the
⊢above requires another
♖move. We need a way to ignore black moves and moves by pieces other than the rook we are looking at.
- We need to make sure that it's the same
♖making the three thematic moves. Maybe white has two rooks and a different rook makes the last move as made the first move.
⊢as written only handles a particular series of squares,
a8-h8-h1-a1. But we want the rook to be able to start from any corner and go in any direction.
Since we want to focus on the motion of only a single rook, we name that rook with a piece variable which we call
T∊♖This will successively assign the variable
T to each square containing a
♖ in the current position, which is to say, to each
♖ in the position. The filter following this expression will then be evaluated with
T set to that square. In this case, the filter following the expression is the
⊢ filter on the next four lines.
◎T is evaluated in the current position,
first the value of
T is evaluated, which will be some single square on which there is a
♖. Only move by that exact piece are considered in the containing
In the Kasparyan study above, when the body of the file is evaluated at the position before
6.♖a8-h8, there is only one rook in the position anyway, on
a8. So the
⊢ will only be evaluated when
T has the value
a8. That designates a particular rook, and moves by pieces other than that rook will be ignored.
Now we come to evaluate the constituents of the
a1――h1 ――h8 ――a8This looks like it allows any piece to move from
h1 and then to
h8 on the next move. But actually, the
⊢ is skipping over any move by any piece other than the particular rook that started on
a8 in the current position. Thus, these constituents actually match any sequence with the same rook moving from
h8 and to
But the actual path taken by the rook in the Kasparyan study is
a8-h8-h1-a1, which is different. How do we get match that path?
The answer is the
flip) filter before the
✵ filter takes one argument, the next filter, in this case the
⊢. It then applies each rotation or reflection of the chessboard (there are 8 possible such transformations) to this
⊢ filter. The
✵ filter actually runs each of these 8 transformed argument filters against the current position, and matches if any of them match.
If we apply the tranformation that reflects the squares of the chessboard about the horizontal bisector, we get the new path filter:
⊢◎T a8――h8 ――h1 ――a1Since this transformed filter does match the Kasparyan study, so does the
T equal to
a8; and thus so does then
T∊♖ filter, and thus so does the entire body.
summaryThis filter illustrates one of the new features in CQL 6.2: the
◎. To write this in CQL 6.1 would have required a more complicated regular expression that explicitly matched 0 or more moves by non-
By the way, it is often the case that when tracking the motion of a particular piece using
⊢◎, that the squares visited by the piece are of interested. You can add a concise description of the movement of such thematic pieces by adding
piecepath to the
⊢◎T piecepath ...
This would output a comment like
R:a8-h8-h1-a1 to the pgn output file.