-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
En-passant erroneously rejected as invalid when specified via SAN #54
Comments
Upon further testing, it looks like the first case works because moves generated via The SAN en passant move maybe is failing because the SAN does not have the |
Examining this loop a bit more, where the parsed SAN is being checked against the full list of legal moves - if the SAN is assumed to be valid (say, SAN from another system that is being played back, which happens to be what I'm trying to do) then checking for takes here and here is redundant, since the list of legal moves with a given source and destination will either be a capture or non-capture; it's not possible to have both capture and non-capture returned as legal moves, so there's no need to do these checks to disambiguate between the two. However, dropping these checks would make the parsing more permissive to nonsensical moves, such as Some possible solutions are:
|
This change modifies the from_san parsing to fix an issue where un-annotated en passant (missing the `e.p.` suffix) is not found as a valid move. This bug stems from the fact that the SAN parser: * records if a proposed move is a capture by looking for the `x` character * matching the proposed move's capture status with whether each legal move is a capture, in a slightly buggy way - by detecting if the destination square holds a piece. En passant is the only capture type during which the destination square doesn't hold the captured piece. When the `e.p.` suffix is present in the input SAN move, this check is skipped; however, the check is not skipped when the suffix is not present, and such an en passant SAN input will fail to match its corresponding legal move. This change drops the check for takes. This will allow en passant SAN inputs to match their corresponding legal move, but it will also alias capture SAN inputs to a non-capture legal move (Nxf3 will be interpreted as Nf3 if Nf3 happens to be legal, rather than being rejected) and vice versa. Since this crate will only be used when we assume the SAN is valid, we don't care about this aliasing. Fixes: jordanbray#54
Chess.js generates the following moves:
https://lichess.org/NlJw2ipp#31 axb6 is an en_passant move and this is the standard notation for it. It being rejected as invalid is definitely a bug. EDIT: Chessjs provides a flag: this can be used to add the necessary suffix " e.p." |
With 3.2.0, the following case prints
test successful
:whereas this case panics with
invalid: dxc6: InvalidSanMove
:As far as I can tell, this is the same move, and valid SAN? (SAN comes from the beginning of https://www.chess.com/game/live/9695070671)
The text was updated successfully, but these errors were encountered: