# consecutivemoves

The`consecutivemoves`

filter takes two position variables in parentheses as arguments, optionally preceded by a range:
consecutivemoves (x y) consecutivemoves 5 1000 (x y)

Suppose the arguments to the `consecutivemoves`

filter are the position variables

and *x*

.
*y*

The `consecutivemoves`

filter first finds the latest common ancestor

of the positions represented by *L*

and *x*

.
*y*

Let

be the sequence of moves from *S*

to *L*

. Let *x*

be the sequence of moves from *T*

to *L*

.
*y*

and *S*

are the
exact moves, in order, played to reach *T*

from *x*

and to reach *L*

from *y*

respectively.
*L*

Thus, the length of

is equal to the
ply value of *S*

minus the ply value of *x*

. Similarly the length of *L*

is the ply value of *T*

minus the ply value of *y*

.
*L*

The filter `consecutivemoves(x y)`

gives the length of the longest sequence of consecutives moves in

that is identical to a sequence of consecutive moves in *S*

.
*T*

If a range is specified, the `consecutivemoves`

filter only matches if that length lies with the range. If either of its argument filters do not match, then neither does the
`consecutivemoves`

filter.

The `consecutivemoves`

filter adds comments to the longest pair of subsequences of consecutive moves that it located (unless the `quiet`

or `silent`

was specified in the CQL header). These comments indicate which move in one subsequence matched which move in the other subsequence.

The `consecutivemoves`

filter is used in locating so-called "logical" studies, where one key move (the move in the LCA position) has a small difference that only becomes apparent much later.

If the parameter `quiet`

is included, the `consecutivemoves`

filter does not
output any comments. (The filter also does not output comments if the quiet is specified in the CQL header):

consecutivemoves quiet 15 100 (source target)

# Examples

The`consecutivemoves`

filter is used in zugzwang2.cql and movedblackpieceecho.cql . In zugzwang2.cql, the `consecutivemoves`

filters is used to find a zugzwang position where the positions differing only in side to move are reached by a series of identical moves.
In the following position from a Didukh study, White can play either `2. Kf3!`

or `2. Kf2`

:

(found from CQL file: zugzwang2.cql)

If White plays `2. Kf3`

the position leads to the following position, which is winning for White:

If on the other hand, white plays `2. Kf2`

, then Black reaches the following the position, which is identical to the position above except that it is white to move instead of black to move:

The sequences of moves to reach the two positions above are the same for 15 consecutive individual moves. For example, from the PGN output for the Didukh study, we see that if White were to play `2. Kf2`

then Black would respond `2...Ne7`

.

Note the comments of the form: `target-move`

or `source-move`

. The comments were generated as a consequence of the filter:

consecutivemoves (source target)>= 5

in the CQL file zugzwang2.cql. It was called when the `source`

was set to the mainline black-to-move position (diagrammed above) after `10. Kf2`

, and `target`

was set to the variation white-to-move position (diagrammed above) after `9...Bb7`

.

The comment `target-move[1]`

means that this is the first (because of the `[1]`

) move of the sequence of moves leading to `target`

. There is a corresponding sequence of moves leading to `source`

, and the first move of that sequence, which is `2...Ne7`

in the mainline, is annotated `source-move[1]`

. Both these moves are the same: `...Ne7`

.

Reading down the moves in the variation and mainline, one can see the correspondence of identical moves between the variation and the mainline.