# purestalemate

The`purestalemate`

filter is true in a position if the position is a pure stalemate. A pure stalemate, loosely speaking, is
one in which there is no unnecessary attack by the mating side on a square adjacent to the mated King.
More formally, a black-to-move position is a pure stalemate if each of the following conditions holds:

- each empty square adjacent to the black king is attacked exactly once by a white piece;
- each white piece adjacent to the black king is attacked exactly once by a white piece;
- each unpinned black piece adjacent to the black king is not attacked by a white piece; and
- each pinned black piece adjacent to the black king is not attacked by a white piece.

A white-to-move pure stalemate is defined similarly.

# Participants: the value of the purestalemate filter

If the current position is a pure stalemate, the value of the`puremate`

filter is the set of squares on which there is a *participating piece*. If the current position is not a pure mate, the value returned is the empty set.

If the current position is a pure stalemate of the black King, the participating white pieces are each white piece that either:

- is pinned;
- is pinning a black piece
- is attacking a square adjacent to the black king.

Every black piece is considered to be a participating piece when black is in stalemate.

If white is in stalemate, the definitions above are modified accordingly.

# modelstalemate

The`modelstalemate`

filter is true if the current position is a *model stalemate*: a pure stalemate in which each non-King, non-pawn piece of the stalemating side participates. Thus,

`modelstalemate`

is true in position whenever
⬓{ btm purestalemate ♖♘♗♕ in purestalemate}

(Note that the first `purestalemate`

in the CQL code above cannot be omitted, because otherwise any black-to-move position that is not a pure stalemate would match if the only white pieces were kings and pawns.)

The value of the `modelstalemate`

filter, like the `purestalemate`

filter, is the set of participants in the model stalemate (or the empty set if there is no model stalemate).

# idealstalemate

The`idealmate`

filter is true if the current position is an *ideal stalemate*: a pure stalemate in which each piece participates. The

`idealstalemate`

filter is equivalent to:
` ◭==purestalemate`