notnil / chess

chess package for go
MIT License
517 stars 130 forks source link

notation: remove extraneous disambiguators when decoding (L)AR #84

Closed sumnerevans closed 2 years ago

sumnerevans commented 2 years ago

Closes #82

This PR adds support for removing unnecessary move disambiguators when decoding a move.

It also makes some refactors to use regexp, and use the same decode logic for long algebraic notation and algebraic notation.

sumnerevans commented 2 years ago

Converting to draft since this causes bugs with parsing things like: bf4 from rnbqkbnr/ppp1pppp/8/3p4/3P4/8/PPP1PPPP/RNBQKBNR w KQkq - 0 2

sumnerevans commented 2 years ago

@notnil I cleaned up that PR and I think it's ready for review now. I added a test for the case that I described in the last comment.

notnil commented 2 years ago

On my computer this slows the parser down from:

BenchmarkPGN-12                              523       2271381 ns/op

to

BenchmarkPGN-12                              312       3853621 ns/op

likely due to regex. I think this is acceptable considering this is a bug that has come up multiple times and it makes the code easier to reason able. Thanks for creating the PR @sumnerevans .