Skip to content

Commit

Permalink
notation: improve parsing to handle pawn moves in (L)AN
Browse files Browse the repository at this point in the history
  • Loading branch information
sumnerevans committed Dec 13, 2021
1 parent 5f0226a commit b230606
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 16 additions & 4 deletions notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions notation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
)

Expand Down

0 comments on commit b230606

Please sign in to comment.