:forany
keyword in a match list. The :forany
keyword takes two parameters: the alphanumeric name of a tag and
a piece designator.
The match filter is then conceptually run once in which each tag is bound to each possible mark, such that two conditions hold:
:tagmatch
keyword in a position list takes two parameters, the name of a tag and a piece designator. The position list match fails on the current position if the piece and square corresponding to the mark of the tag does not match the given piece designator. For example, assuming there is a tag named "foo", this position will only match if
"foo" is a white pawn:
(position :tagmatch foo P)
(position $foo[a1,d4])The piece represented by the tag named "foo" must be on
a1
or d4
.
; Find all games in which the same rook visits all four corners of the board. (match :pgn heijden.pgn :output out.pgn :forany rook [rR] ; loop over the possible rooks (position $rook[a1]) (position $rook[h1]) (position $rook[h8]) (position $rook[a8]) )Here, the
:forany
keyword in the match list introduces a tag named rook
which is constrained to range over white or black rooks, or over pawns that
eventually promote to one of those.
The first position list matches games in which there is a position such that the tag rook
represents a rook on a1. The next position list matches games
in which there is a postiion such that the tag represents a rook on h1. The tag represents the same mark, that is, the same piece, between the position lists.
The :forany
keyword will sequentially bind the tag to each allowed mark.
Since a match list matches a game only if all its constituent position filters match it, the code does what we want here.