notnil / chess

chess package for go
MIT License
508 stars 126 forks source link

multidecoder when decode PGN cause invalid board state #118

Open thangng48 opened 1 year ago

thangng48 commented 1 year ago
g := chess.NewGame(chess.UseNotation(chess.UCINotation{}))
pie(g.MoveStr("g1f3"))
pie(g.MoveStr("e7e5"))

fmt.Println(g.String()) // 1. g1f3 e7e5  *

pgn, err := chess.PGN(strings.NewReader(g.String()))
if err != nil {
   panic(err)
}

g2 := chess.NewGame(chess.UseNotation(chess.UCINotation{}), pgn)
fmt.Println(g2.String()) // 1. f2f3 e7e5  *

When decoding https://github.com/notnil/chess/blob/e9ff96c9f2d309a51c820bc3068f2c4ec473664c/pgn.go#L168, it tries every possible decoder and stop at not nil one. Above example shows that it can cause invalid board state.