chess icon indicating copy to clipboard operation
chess copied to clipboard

Normalise en passant square returned by `Board::en_passant`

Open kraktus opened this issue 5 years ago • 2 comments
trafficstars

Hello,

Currently the square returned by Board::en_passant is on the fifth or the fourth rank, which is not standard.

What is expected to be returned by the Board::en_passant is the en passant target square which is on the third or sixth rank (in the example given by the docs it should be e6 instead of e5).

This change would also make checking if a given move is en passant easier.

The en passant target square is the way en passant is set by FEN, I think we should follow the standard.

Of course that would be a breaking (albeit small) change.

Thanks for your time developing and maintaining this library.

kraktus avatar Sep 07 '20 18:09 kraktus

That's an interesting idea. I'll take a look at it sometime this week. Keep in mind you can easily transform the result from what it is to what you want with the Square::ubackward(&self, color: Color) -> Square function.

As for actually implementing this change, because it is a breaking change, I think en_passant must do what it has always done, perhaps with a deprecation message, and a new function en_passant_target? should probably be added. This, despite technically being semver incompatible, I'd feel comfortable pushing with a minor version change.

As for whether it is easier, I can definitely see that (if dest == en_passant_target), I'd be curious if it turns into a performance impact. It's probably minimal if present at all, because en_passant moves are so rare.

jordanbray avatar Sep 08 '20 20:09 jordanbray

Thanks for your interest, yes I currently use a workaround with Square::ubackward.

I agree with a new function en_passant_target which will make the change much easier to deploy as non-breaking.

I think the current ep square returned by the library was chosen as it is simpler to set: https://github.com/jordanbray/chess/blob/70461cafa92d3995fd14256c50526e1060bbb80f/src/board.rs#L952

kraktus avatar Sep 11 '20 12:09 kraktus