# flip

`flip`

is a transform filter corresponding to the following 8 basic transforms.
**id**, the identity**rotate**: counterclockwise rotation about the board center by 90°_{90}**rotate**: rotation by 180° about the board center_{180}**rotate**: clockwise rotation about the board center by 90°_{270}**reflect**: reflection about the horizontal bisector._{h}**reflect**: reflection about the vertical bisector._{v}**reflect**reflection about the_{a1h8}`a1-h8`

diagonal.**reflect**: reflection about the_{h1a8}`h1-a8`

diagonal.

These are called dihedral transforms because they arise from the rigid transformations of a chessboard into itself.

`flip`

is normally called with a single argument filter, *F*:

flipF

`flip`

also accepts an optional `count`

parameter.
`flip `

matches the current position if any transformation of *F**F* by one of the 8 basic transforms above matches the current position.

For example, suppose *F* is the filter `{Ka1 kh8}`

, matching a position in which the white king is on `a1`

and the black king is on `h8`

. If we transform this filter by **reflect _{h}** we get the new filter

`{Ka8 kh1}`

. The filters that results from transforming `{Ka1 kh8}`

by all the elements of `flip`

, which is to say all the reflections and rotations of the board including the identity, are:
{Ka1 kh8} {Kh1 ka8} {Ka8 kh1} {Kh8 ka1}

The filter `flip {Ka1 kh8}`

will thus match a position if any of these four filters match the position, that is, if the kings are on opposite corners in the current position. (This can also be done, much more efficiently, using `k==diagonal 7 K`

)

If *F* is a set filter then so is

flipF

in which case its value is the union of the values of each of the sets represented by each transformed version of *F*.

For example,

`flip a1`

is the set `[a1,h1,a8,h8]`

.

If *F* is a numeric filter then so is `flip `

in which case its value is the maximum of the values of all the values of the matching transformed versions of *F**F*.

flip countF

is a numeric filter whose value is the number of distinct matching transformed versions of *F*. For example, if the current position is the initial position, then

flip count find {Qa1 qh8}

is the number of distinct configurations of the white and black queens on opposite corners that occur in a game. In other words, this is the number of corner squares such that there is some position in the game in which a white queen is on that corner and a black queen on the opposite corner.

The `flip`

filter also modifies directions parameters and filters. Thus,

flip ray up (R K)

will match if and only if

ray orthogonal (R K)

matches.

# Examples

`flip`

is used in staircase.cql and staircase-sort.cql , which find staircase maneuvers by the queen. There, a staircase is defined using a particular pair of directions, and `flip`

is used to generate all the other directions.