Skip to content
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

PGN's Reader? #77

Closed
pokemonchw opened this issue Sep 1, 2021 · 3 comments · Fixed by #86
Closed

PGN's Reader? #77

pokemonchw opened this issue Sep 1, 2021 · 3 comments · Fixed by #86

Comments

@pokemonchw
Copy link

pokemonchw commented Sep 1, 2021

`

func main() {

    pgn, err := chess.PGN(strings.NewReader("\n1. d4 d5 2. Bf4 Nc6 3. e3 Qd6 4. Bxd6 exd6 5. Nc3 Nf6 6. Qf3 Bg4 7. Qf4 O-O-O 8. Nb1 Nb4 9. c3 Nxa2 10. Rxa2 Re8 11. f3 Bd7 12. h3 Nh5 13. Qxf7 Rxe3+ 14. Be2 Ng3 15. b4 Nxh1 16. Rxa7 Ng3 17. Ra8# 1-0"))

    if err != nil {

            fmt.Println(err.Error())

    }

    game := chess.NewGame(pgn)

    a := game.String()

    fmt.Println(a)

    _, err = chess.PGN(strings.NewReader(a))

    fmt.Println(err.Error())

}
`

now, its output:

`
1.d4 d5 2.Bf4 Nc6 3.e3 Qd6 4.Bxd6 exd6 5.Nc3 Nf6 6.Qf3 Bg4 7.Qf4 O-O-O 8.Nb1 Nb4 9.c3 Nxa2 10.Rxa2 Re8 11.f3 Bd7 12.h3 Nh5 13.Qxf7 Rxe3+ 14.Be2 Ng3 15.b4 Nxh1 16.Rxa7 Ng3 17.Ra8# 1-0

chess: pgn decode error chess: failed to decode notation text "1.d4" for position rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 on move 1

`

@amanjpro
Copy link

amanjpro commented Sep 7, 2021

Oh, this issue is a different form of #78, but unfortunately #79 only fixes #78 not this one

@notnil
Copy link
Owner

notnil commented Sep 8, 2021

Playground:
https://play.golang.org/p/mw2VF__sTap

Its strange that adding it to the fixtures/pgn folder and including it in a test DOESN'T cause the issue. Something along the line (unique to the chess.PGN entry point) is trimming the space between 1. and d4.

@sumnerevans
Copy link
Contributor

I was able to reproduce this minimally:

package main

import (
	"log"
	"strings"

	"github.com/notnil/chess"
)

func main() {
	game := chess.NewGame()
	game.MoveStr("d4")
	pgn, err := chess.PGN(strings.NewReader(game.String()))
	if err != nil {
		log.Fatal(err)
	}
	newGame := chess.NewGame(pgn)
	log.Printf(newGame.FEN())
}

It seems like the PGN parser doesn't handle when there's no space between the number and the algebraic notation.

sumnerevans added a commit to sumnerevans/chess that referenced this issue Dec 12, 2021
There were two main bugs that this fixes.

* Fixes notnil#77: fixed parsing of PGNs where there is no space after the
  move number indicator. This used to work, but notnil#76 caused a regression.

* Fixes notnil#78: using the regular expression allows for comments that don't
  have spaces separating the `{` and `}` tokens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants