32

I am trying to write a simple chess program, and as part of this I am writing methods to find all valid moves. I can detect pins and have no trouble leaving out the moves that would result in the moving player being in check, except for one situation I am not sure about.

After an en passant capture, not only is the square previously occupied by the capturing pawn now vacant, but so is the square of the captured pawn. Is there any position at all where capturing en passant results in a discovered check on the king of the player that is capturing en passant, not because the capturing pawn was pinned, but because the check was previously stopped by the captured pawn?

I think this situation is simply not possible, at the very least I can't think of a position and series of moves that results in this situation; the fact that you have to capture en passant at the first opportunity means that either the pawn that should later capture en passant is pinned and can't advance to the fifth rank, or the check is blocked by a different piece anyway. Unfortunately I am having trouble ruling out there is some counter-intuitive position where this might happen. Could someone confirm my suspicions (or provide a counter-example)?

11684
  • 1,296
  • 11
  • 23
  • 3
    Let's say the captured pawn is black. If it was blocking a check on white, it means that white was in check before the black pawn move, which means that white was in check after white's last move, which would be illegal. Therefore it is not possible for a pawn that can be captured en passant to block a check on the opponent's king. – itub Aug 25 '17 at 16:08
  • 4
    You might enjoy https://ericlippert.com/2017/02/13/why-should-i-be-worried-about-dying/. The answer is here: https://ericlippert.com/2017/02/14/the-chess-mystery-solved/ – Eric Lippert Aug 25 '17 at 20:37
  • @bof Thank you, but that is actually not what I meant. This part is not clear in the question, I will edit it now. – 11684 Aug 26 '17 at 09:14
  • The question is asking about pins, but the title still asks about discovered checks. – bof Aug 26 '17 at 09:28
  • @bof No, not really. The situation where the pawn capturing en passant was pinned is not a problem; it's just a standard pin. I mean the situation where a check that would have been blocked if the captured pawn was still there, putting the king of the capturing player in check. – 11684 Aug 26 '17 at 09:35
  • I would say that the player whose pawn is being captured couldn't pin its own pawn though it is a question of definition; I agree that it is very pin-like, but the captured pawn would be allowed to move and hence is not pinned IMO (since when the pawn moves the player being in check would not have the move). The fact that en passant allows you to 'move' a piece, or rather, vacate a square of the opponent makes it so difficult to deal with. – 11684 Aug 26 '17 at 09:35
  • Although this is a question of definition as well, I disagree with limiting discovered checks to checks on the opposing king. Obviously, this is the only legal variant, but I would argue that the kind of check I mean is a check, and is discovered. @bof – 11684 Aug 26 '17 at 11:13
  • I think it comes down to the fact that I am trying to describe an illegal situation, which means there is no "correct" terminology. I think there is no other option but to misappropriate an existing term. – 11684 Aug 26 '17 at 11:15
  • But what title would you suggest? If not pin, then what? @bof – 11684 Aug 26 '17 at 11:26
  • One way to think of capturing en passant is that the captured pawn never reached the fourth rank, it was intercepted on the third rank. But, with the enemy pawn on the third rank, your pawn is in a common ordinary pin. – bof Aug 26 '17 at 11:28
  • @bof no, I'm talking about a "pin" on the pawn that is being taken, not on the capturing pawn. – 11684 Aug 26 '17 at 11:30
  • I would define a pin as a situation where a move (by a man other than the king) is illegal because it would expose its own king to check. – bof Aug 26 '17 at 11:30
  • Oh, that's a neat definition. Also, your comment about considering the position with the pawn on the 3rd instead of the fourth rank might really simplify my code. Thanks a lot! @bof – 11684 Aug 26 '17 at 11:33
  • @11684 the simplification with the third rank is not correct, the pawn could well move forwards and that would not expose it's king to a check. It is a kind of half pin :-) – IA Petr Harasimovic Aug 26 '17 at 22:17
  • @bof that definition fails in this situation since the pawn can move forwards therefore it is not pinned. Yet capturing en passant would be illegal. – IA Petr Harasimovic Aug 26 '17 at 22:19
  • 1
    @IAPetrHarasimovic Does the definition of a pin require that the pinned piece be unable to move in any direction? In the position after 1.e4 e5 2.f4 exf4 3.Nf3 Qe6 4.Bb6 Qxe4+ 5.Kf2 Nf6 I think most players would say that 6.Re1 "pins" the black queen, although she is free to move forwards and backwards. – bof Aug 26 '17 at 22:41
  • @IAPetrHarasimovic I'm with bof here; I see a pin as a blocked attack which limits the movement of a piece. Even if said piece can move in the same line as the pin, its moves are nonetheless limited and the piece is therefore pinned. – 11684 Aug 26 '17 at 23:57
  • @bof I just pointed out that in a position like W: Ka5, d5; B: Rh5, e5 according to bof's definition the d5 pawn would be both pinned and unpinned. That's all. I am not aware of any exact definition of a pin but I would say that pin is usually considered such a situation that a piece is attacked and cannot move away because it would expose its King to a check. In the situation discussed the pawn is not attacked therefore this would not be considered a pin (at least the pin that I am used to). But as you said you can probably define the pin in different ways. – IA Petr Harasimovic Aug 27 '17 at 16:06
  • Here is another position, very interesting from a theoretical point of view but of no practical importance. Say in Fisher chess you have W: Ke1, Rb1; B: Ra1. Clearly the Rook is pinned but what is interesting is that castling long is not possible because it would expose the King to a check. And that is even though the square c1 is not attacked. – IA Petr Harasimovic Aug 27 '17 at 16:13
  • One more thought on the pins, the pawns could actually be swapped. Then the pawn would be attacked but it could still move forwards allowing it to escape from the attack. Thus according to my definition it would not be pinned. Not sure about @bof's definition, it still not clear to me what exactly it says. You would have two options either move the pawn forward or capture en passant. One is legal the other is not. Bof would consider this a pin I guess. – IA Petr Harasimovic Aug 27 '17 at 16:23

4 Answers4

37

Really interesting question. I think the following shows that such a situation is sort of possible, depending on how you define the pin.

[StartFlipped "0"]
[FEN "7k/4p3/8/2KP3r/8/8/8/8 b - - 0 1"]

1... e5 2. dxe6?! {Illegal move!}

Now, 2. dxe6 is illegal. The check would go from being stopped by both pawns, to being stopped by neither.

Rewan Demontay
  • 17,514
  • 4
  • 67
  • 113
Cleveland
  • 7,584
  • 1
  • 28
  • 39
  • 2
    Incidentally, this is not how I would have defined a pin when writing the question, but this is exactly what I wanted to know. A better formulation for my question I realise now is if it is safe to assume capturing en passant is always legal (i.e. you don't put your king in check by an en passant capture) if 1) the conditions for capturing en passant are met and 2) the capturing pawn is not pinned. Both of which are met by your counterexample, but ex6 is still illegal. Many thanks! – 11684 Aug 25 '17 at 16:29
  • 2
    I can't see the position on my phone, I am assuming it exhibits a rook on the same horizontal as both pawns. Theoretically the pawn being captured could also be blocking a bishop. That would have the same effect but such a position couldn't occur if all preceding moves were legal. Yet at least as a test case the procedure should detect such an illegal move too. – IA Petr Harasimovic Aug 26 '17 at 22:10
  • 1
    @IAPetrHarasimovic Maybe if it were a high-profile would-be Stockfish competitor, but I'm just programming this because it's fun :) Nonetheless, the way it's programmed now should detect what you're describing as well. – 11684 Aug 27 '17 at 16:16
10

On a related note, enjoy a chess problem that demonstrates the weird mechanism of the pawn being pinned by the taken pawn. I pulled this from Yet Another Chess Problem Database.

[Title "Erich Anselm Brunner, Deutsches Wochenschach 12/1908, Selfmate In 3"]
[FEN "8/8/5Q2/2p3Pk/5R1P/5r2/1PPKB1P1/2NRB3 w - - 0 1"]
  1. Ra4! c4 2. Qf7+ Kg4 3. b4 c3#

The rook on a4 pins the Black pawn such that it cannot take en passant, as that would expose the Black king to check. As such, Black pawn cannot perform an en passant and must move forward with a mate.

Rewan Demontay
  • 17,514
  • 4
  • 67
  • 113
3

Just to clarify IA Petr Harasimovic's comment in the answer provided by Cleveland, here is a position in which capturing en passant is illegal due a diagonal pin.


[FEN "5k2/2p2b2/8/3P4/8/2K5/8/8 w - - 0 1"]

1. Kc4 c5
Rewan Demontay
  • 17,514
  • 4
  • 67
  • 113
Mike Jones
  • 5,169
  • 15
  • 19
0

It's possible, but you need to check who's getting checked ( slight pun intended... :-) ).

Let's say it's black's move:

Black moves a pawn two ranks, opening it up to an en passant move from a white pawn. If this move leads to a check on the black king it's an illegal move. If this leads to a check on the white king, white must respond be defending the king and so can't do an en passant move unless that move will protect the king.

If no check is made, white can then make the en passant move. If this leads to a check on the white king it's an illegal move. If it leads to a check on the black king, black must respond by defending the king.

f2k
  • 17
  • 3
  • 1
    I'm not sure I completely understand your answer, but the way I read it it doesn't answer the question. "If this leads to a check on the white king..." The whole question is whether that could occur, not whether exposing your own king to a check with your move is legal. – 11684 Aug 25 '17 at 23:04
  • My point was that yes, it could happen - as others have showed.

    You didn't specify if you were concerned about getting yourself in check or getting your opponent in check, hence I looked at all the possibilities, noting that some of them were ilegal moves.

    Long story short, an en passant move can indeed set the opposing king in check, but never your own as that would be an ilegal move.

    Sorry if that wasn't entirely clear.

    – f2k Aug 26 '17 at 08:47
  • Then this doesn't answer the question. I am aware of the consequences pertaining to the legality of a move, I only wanted to know whether a position where the king of the player capturing en passant would be in check. – 11684 Aug 26 '17 at 09:11
  • I'm honestly not sure what your asking anymore.

    If you're aware of the issue of the legality of the move, then you should know that no move may put your own king in check.

    Can you make an en passant capture that puts your own king in check? No, of course not.

    Can you make an en passant capture that puts your opponent's king in check? Yes, you can.

    – f2k Aug 26 '17 at 15:05
  • @f2& I'm asking whether there exists a position in which an en passant capture could be made, made illegal only by the fact that it would expose your own king to a check over the square that was previously occupied by the now captured pawn. – 11684 Aug 26 '17 at 17:34
  • 2
    He is asking whether it is safe to assume that taking en passant can never expose your own king to a check. Your answer is that en passant capture cannot expose one's king to a check but it is not correct, it would be possible in some positions. – IA Petr Harasimovic Aug 26 '17 at 22:02