En Passant Legality

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
cms271828
Posts: 316
Joined: Wed Apr 12, 2006 10:47 pm

En Passant Legality

Post by cms271828 »

Hi, I'm trying to fix a bug in my ep.

During move generation (say for white pawns), we have an ep capture if the last move was a black pawn moving 2, which has a white pawn on 1 or both sides of it.

My confusion came from the fact that when the black pawn is removed, it could open a discovery check on the white king, making the move illegal.

But thinking about it, the current position must be unreachable, since on blacks turn, it would have had (say a bishop) already attacking the white king which makes no sense.

So my point is, if we disallow these types of unreachable positions in setup mode, then the ep capture is just like any other, and we test it for legality as normal.

Is that right? Thanks
Colin
User avatar
Zach Wegner
Posts: 1922
Joined: Thu Mar 09, 2006 12:51 am
Location: Earth

Re: En Passant Legality

Post by Zach Wegner »

You are right about diagonal attacks, but it can still be illegal if there is a horizontal attack that goes across both pawns on the 5th rank.
User avatar
cms271828
Posts: 316
Joined: Wed Apr 12, 2006 10:47 pm

Re: En Passant Legality

Post by cms271828 »

Thats a good point, cause the white pawn could be pinned horizontally to white king by a black rook/queen on the 5th rank, then when the black pawn moves 2 the white pawn is unpinned, but will be unable to capture ep.

My current system would fail here, since it would look at the position with the white pawn removed to see if king is attacked, which it would establish to be 'no' as the line is blocked by a black pawn.

But obviously the black pawn should be removed too, so I need to rewrite some code.
Colin
Fguy64
Posts: 814
Joined: Sat May 09, 2009 4:51 pm
Location: Toronto

Re: En Passant Legality

Post by Fguy64 »

Hi Colin

I just wanted to bring the following thread about en-passant to your attention. Maybe you will find it useful, I don't know.

http://www.talkchess.com/forum/viewtopi ... ht=passant