user674: 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)?

user9684: 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


user15543: 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.

user3270: 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.

674: <p>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.</p>

<p>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 <strong>on the king of the player that is capturing en passant</strong>, not because the capturing pawn was pinned, but because the check was previously stopped by the captured pawn?</p>

<p>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)?</p>
 9684: <p>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.</p>

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

1. Kc4 c5
</code></pre>
 15543: <p>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 <a href="https://www.yacpdb.org/#86389" rel="nofollow noreferrer">Yet Another Chess Problem Database.</a></p>
<pre><code>[Title &quot;Erich Anselm Brunner, Deutsches Wochenschach 12/1908, Selfmate In 3&quot;]
[FEN &quot;8/8/5Q2/2p3Pk/5R1P/5r2/1PPKB1P1/2NRB3 w - - 0 1&quot;]

1. Ra4! c4 2. Qf7+ Kg4 3. b4 c3#
</code></pre>
<p>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.</p>
 3270: <p>Really interesting question. I think the following shows that such a situation is sort of possible, depending on how you define the pin.</p>
<pre><code>[StartFlipped &quot;0&quot;]
[FEN &quot;7k/4p3/8/2KP3r/8/8/8/8 b - - 0 1&quot;]

1... e5 2. dxe6?! {Illegal move!}
</code></pre>
<p>Now, 2. dxe6 is illegal. The check would go from being stopped by both pawns, to being stopped by neither.</p>
