Check

From Chessprogramming wiki
Jump to: navigation, search

Home * Chess * Check

Samuel Bak - Lighthouse [1]

Inside a game of chess, a check occurs if a king is under immediate attack by one (or two) opponent pieces. If the king has no way to remove it from attack on the next move, the check is even checkmate. Since check is crucial concerning the outcome of game and the horizon effect, check extensions might be applied to evade the check.

Kind of Checks

Single Check

The king is attacked by one opponent piece, either by the piece which just moved directly attacking the king, or alternatively a discovered check where a distant sliding piece attacks the king by opening the ray in opponent king direction with another piece.

Double Check

A double check occurs if the moving piece directly attacks the king but also discovers a distant sliding attacker.

In Check Detection

Whether the side to move is in check is essential to know inside the search for various reasons. It might be checkmate, and most pseudo-legal moves generated may be illegal, leaving the king attacked. Null move would yield in an illegal position as well, at or below the horizon we don't want to stand pat if material balance or static evaluation is far greater than beta.

By last Move

The cheapest and most straightforward way to detect checks is to consider the previous move just made by the opponent. It might be a direct check or discovered check, so one has to test whether piece on target square attacks the king, or whether piece on origin square is attacked by an own sliding piece on an otherwise open ray in opponent king direction [2]. If the last move was an en passant capture, one has to consider a few more complicated cases of possible discovered checks, since the captured pawn is not on the target square, and two pawns disappear from the 4th (5th) rank.

Attack Tables

Based on the design and data structure of a chess program, an incremental updated attack and defend map may immedeatly answer whether the king is under attack of one or even two opponent pieces.

On the Fly

With bitboards one may determine a square attacked as mentioned in checks and pinned pieces.

Getting out of check

While in check, it is recommended to perform a specialized Move Generation for check evasion of either a reasonable subset of all pseudo-legal moves or even a strict legal move generation:

Double Check

  • Only king moves to non attacked squares, sliding check x-rays the king

Single Check

  • Capture of checking piece. The capturing piece is not absolutely pinned
  • King moves to non attacked squares, sliding check x-rays the king
  • Interposing moves in case of distant sliding check. The moving piece is not absolutely pinned.

Perpetual Check

A perpetual check occurs if one player forces an "endless" series of checks with repeated reversible moves, finally resulting in a draw by threefold repetitions.

See also

Publications

Forum Posts

1997 ...

2000 ...

2005 ...

2010 ...

2015 ...

2020 ...

External Links

References

Up one Level