flip

flip is a transform filter corresponding to the following 8 basic transforms.
  • id, the identity
  • rotate90: counterclockwise rotation about the board center by 90°
  • rotate180: rotation by 180° about the board center
  • rotate270: clockwise rotation about the board center by 90°
  • reflecth: reflection about the horizontal bisector.
  • reflectv: reflection about the vertical bisector.
  • reflecta1h8 reflection about the a1-h8 diagonal.
  • reflecth1a8: reflection about the 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:

      flip F

flip also accepts an optional count parameter. flip F matches the current position if any transformation of 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 reflecth 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

flip F

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 F in which case its value is the maximum of the values of all the values of the matching transformed versions of F.

flip count F

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.