The Curious Case of the Illegal Double Check

Azlan Iqbal
9 min readJul 13, 2022


In chess, the ‘double check’ theme occurs when two pieces give simultaneous check to the enemy king. Fig. 1 shows an example of it.

Figure 1: The double check.

Had the knight moved from the b7 square to a5 instead, it would be a discovered check. If the target of such a move is not the king but some other enemy piece it would simply be, more generally, a double attack. If the king got checkmated as a result of the maneuver, it would be a double checkmate. The double check is a particularly powerful maneuver because the king must move. Typically, another piece could intervene between the king and the piece giving check to it, but when there are two pieces giving check simultaneously, the only way to escape is for the king itself to be moved. And if there are no available squares to move to… that would be checkmate.

An illegal double check occurs when the position itself is not possible, i.e., it could not have arisen in a real game. Not just unlikely to have arisen, but it simply could not have occurred according to the rules of chess. An example is shown in Fig. 2.

Figure 2: An illegal double check.

In this case, the white king would have already been in a state of check when the knight moved to f2 to check it again. The same is true had there been instead a black pawn on b7 that captured a white piece on a8 and underpromoted to bishop, simultaneously giving check. Detailed retrograde analysis is not required to see the obvious illegality of this position. Interestingly, even some modern chess engines like Stockfish 15 (e.g., via the ChessBase 13 software interface, see Fig. 3) are not programmed to recognize such positions (including certain other types) as illegal.

Figure 3: Stockfish 15 accepting and processing the illegal position shown in Fig. 2.

And why should they? The position could not arise in a real game and the engine certainly would not allow it to happen in one. That is true, but in automatic chess problem composition such as done by Chesthetica, for instance, there are no prior moves and such positions, standing alone, could indeed occur during the composing process. Therefore, they need to be detectable, and potentially filtered out or rejected. Even a human composer might unwittingly make the same mistake sometimes in the process of composing.

On a side note, I tend to recall some older chess engines (maybe some exist to this day) not even supporting pawn promotion to anything other than a queen presumably because underpromotions, in real games at least, are exceedingly rare. Not so in compositions, however. In some cases, underpromotion is actually necessary in a real game, e.g., to avoid a stalemate or win more quickly under time controls. In any case, the illegal double check, while rare in automatic chess problem or puzzle composition, can and does indeed occur. Not accounting for them sufficiently can be problematic down the line.

The challenge, academic as it may be, therefore lies in their proper computational or algorithmic detection… and this is more complicated than one might expect. The example shown in Fig. 2 is a trivial one and these can be detected using the following simplified steps.

  1. Scan the board (e.g., upper left to lower right) for enemy pieces that attack the king. In this article, we shall assume it is the white king under attack.
  2. If there is just one such (black) piece or more than two of them, the position does not contain a double check or it is clearly illegal, so reject it immediately.
  3. If there are exactly two such pieces, determine if they are short-range pieces (e.g., two pawns, two knights) and if so, reject the position as illegal because there is no way one created the discovered check of the other.
  4. If these two pieces include at least one long-range piece (e.g., bishop, rook, queen), determine if the other checking piece (e.g., pawn, knight) could have legally moved to its present square from any of the intervening squares between that long-range piece and the white king. Prior to moving, the position should not have the white king in check at all since the short-range piece was blocking the long-range one (as in Fig. 1 before the knight moved from b7 to d6 and unlike Fig. 2 where it is not possible). If true, the double check is (theoretically) legal.
  5. If the two pieces are both long-range, the process above needs to be repeated for the other piece as well, i.e., to determine also if the second checking piece could have legally moved to its present square from any of the intervening squares between the first checking piece and the white king. If either test results in a position where the white king was not in check, the double check is legal. Fig. 4 shows an example. While the rook could not have occupied c4 in the move prior, the bishop may have occupied d7. (Note that it could also have occupied that square if the black king was on a5 instead and a white rook was on h5, pinning it). Interestingly, in most cases, if the two long-range pieces are of the same type (e.g., two queens, two rooks, two bishops), the double check would not be legal.
Figure 4: Two long-range pieces create a legal double check.

Fig. 5 shows an example of two different long-range pieces delivering a double check, yet the position is illegal because even if the queen could have occupied one of the intervening squares between the rook and king (i.e., d6), the latter would already have been in check from the queen. If the rook was on d5 instead of d8, however, the position would be legal because the rook could have moved from b5 to d5, creating the double check.

Figure 5: Two different long-range pieces in an illegal double check.

Now, here is where things get more complicated. Consider the position shown in Fig. 6. The position is clearly illegal because the knight could not have previously occupied any of the intervening squares between the rook and white king.

Figure 6: An illegal double check.

But what about the position in Fig. 7? It looks very similar to Fig. 6 yet it is legal. The reason is that in the hypothetical previous move or position, there might have been a black pawn on c2 that underpromoted to a knight.

Figure 7: A legal double check.

Algorithmically, for cases like this, one would therefore have to test for positions in which both the white king and the first checking piece are on the second rank, and that the square immediately above the second checking piece (the knight in this case) could have been a black pawn. Reversing the position to that state would leave the white king free of checks. If true, then the double check in the position is considered legal. It would not be true, for instance, if the knight in Fig. 7 was on g1 instead. Somewhat similarly, the position in Fig. 8 may appear to be illegal, but it is not even though both checking pieces are long-range and of the same type.

Figure 8: A legal double check.

The reason for this is that in the prior position, there might have been a black pawn on e2 and no rook on d1, but rather a white piece there. The black pawn captured that piece and underpromoted to the rook, creating the unusual double check. Algorithmically, one would therefore have to test for positions where the white king and one of the checking pieces (which must be to its immediate right or left) are on the first rank. The square above the king could have been a black pawn (in this case, with the rook on d1 replaced by a theoretical white piece) which left the position in a state of no check on the white king. If true, then the double check is considered legal. But it does not end there. Study the position in Fig. 9. It looks remarkably similar to Fig. 5 yet this one is theoretically legal.

Figure 9: A legal double check.

The reason now is the pawn that happens to be beside the king. What might have happened here is that in the previous move, Black created a two-way discovered check. A very rare occurrence but possible and completely legal nonetheless. Fig. 10 shows what the position, in the previous move, could have looked like.

Figure 10: The hypothetical position just prior to Fig. 9.

Here, going back one step further, one could imagine the white pawn on c2 instead of c4 and the queen moving from say, e6 to a6 giving check. The white pawn advances two squares to c4 to block the queen and this allows the black pawn on d4 to capture it en passant, resulting in the position seen in Fig. 9. The simultaneous checks on the white king are both ‘discovered’ since both pawns are removed from the lines that blocked those checking pieces. Therefore, in order to detect this type of double check, one would have to test for positions where the white king is on the third rank with an enemy pawn to its immediate left or right; not to be confused with something like in Fig. 4 where no pawn exists.

That (black) pawn, should it exist, would need to be removed and placed immediately ‘above’ the white king with a new white pawn immediately above where the black pawn used to be. Should that position result in a state where the white king is not in check, then the double check is legal. To be thorough, since the white pawn advances two squares, there should also be no pieces ‘behind’ the white pawn (c2 in this case) because then it could not have advanced those two squares. For example, in Fig. 9, if there was a white knight on c2, the position would be illegal because the white pawn could not have advanced to c4, blocking the queen.

It is quite possible that there are even more variations of the illegal double check that I have not considered here that would require even more programming to properly cater for. A double check where both kings are in check simultaneously can also be set up (see Fig. 11). Here, the knight somehow moved from d6 to b5 delivering the double check, but illegally exposing its own king to check. One could theoretically set up this position manually (FEN: 3r4/8/1k5R/1n6/3K4/8/8/8 w — — 0 1) and feed the position notation string into an engine. The result I got with Stockfish 15 was drawish with the main line suggestion of 1. Ke5 followed by 1. … Nd4. The engine going haywire, it would seem.

Figure 11: Illegal double check by Black with both kings illegally in check.

In any case, I am fairly confident the examples and detection steps provided here cover the vast majority of illegal double checks conceivable. Sufficient if you intend to develop a program that composes its own chess problems or puzzles, or one that evaluates the double check theme computationally for whatever reason. You should not rely solely on an external chess engine to detect and reject illegal positions like these. Besides, sometimes, a little good old-fashioned artificial intelligence (GOFAI) in the right place is more effective and practical than a cumbersome machine learning subsystem.



Azlan Iqbal

Artificial intelligence researcher and senior lecturer at College of Computing & Informatics, Universiti Tenaga Nasional, Malaysia.