diff --git a/notation.go b/notation.go index 7708134..8e64766 100644 --- a/notation.go +++ b/notation.go @@ -152,11 +152,23 @@ func (AlgebraicNotation) Decode(pos *Position, s string) (*Move, error) { // Try and remove the disambiguators and see if it parses. Sometimes they // get extraneously added. - options := []string{ - piece + originRank + capture + file + rank + promotes + castles, // no origin file - piece + originFile + capture + file + rank + promotes + castles, // no origin rank - piece + capture + file + rank + promotes + castles, // no origin + options := []string{} + + if piece != "" { + options = append(options, piece+capture+file+rank+promotes+castles) // no origin + options = append(options, piece+originRank+capture+file+rank+promotes+castles) // no origin file + options = append(options, piece+originFile+capture+file+rank+promotes+castles) // no origin rank + } else { + if capture != "" { + // Possibly a pawn capture. In order to parse things like d4xe5, we need + // to try parsing without the rank. + options = append(options, piece+originFile+capture+file+rank+promotes+castles) // no origin rank + } + if originFile != "" && originRank != "" { + options = append(options, piece+capture+file+rank+promotes+castles) // no origin + } } + for _, opt := range options { if opt == moveCleaned { return m, nil diff --git a/notation_test.go b/notation_test.go index bc802a1..c005904 100644 --- a/notation_test.go +++ b/notation_test.go @@ -100,6 +100,12 @@ var ( Pos: unsafeFEN("rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e6 0 2"), Text: "nf3", }, + { + // disambiguation should not allow for this since it is not a capture + N: AlgebraicNotation{}, + Pos: unsafeFEN("rnbqkbnr/ppp1pppp/8/3p4/3P4/8/PPP1PPPP/RNBQKBNR w KQkq - 0 2"), + Text: "bf4", + }, } )