if

The if filter has one of two forms:
    if condition then then
    if condition then then else else

Each of condition, then and else is a filter. For example,

    if R>2 then check
    if A attacks k then mate else Q

The meaning of the if filter in a position is as follows:

  1. If condition matches the position then then is evaluated in the position.
  2. If condition does not match however and else is present, then else is evaluated in the position

when an if filter matches a position

An if filter matches a position if one of the following is true:
  1. condition and then both match the position
  2. condition does not match the position and there is no else
  3. condition does not match the position and else matches the position

Note that point 2 above might be suprising: an if filter without an else matches a position if the condition does not match:

       if check then R>2
will match the current position if either
  • The current position is not a check, or
  • The current position is a check and there are at least three white rooks in the position

The value associated with an if filter

An if filter has an associated value if
  1. it has both then and else
  2. it matches the position
  3. Its then and else are both numeric filters, both position filters, or both set filters.
When an if filter matches a position, its value is the value of its then or its else , depending on whether its condition matched or failed to match the position.

Examples

The if filter is used in idealmate.cql, modelmate.cql, persistent.cql, puremate.cql.