diff --git a/game.go b/game.go index 67f7cd2..7fab860 100644 --- a/game.go +++ b/game.go @@ -164,6 +164,7 @@ func (g *Game) Move(m *Move) error { g.moves = append(g.moves, valid) g.pos = g.pos.Update(valid) g.positions = append(g.positions, g.pos) + g.comments = append(g.comments, []string{}) g.updatePosition() return nil } diff --git a/game_test.go b/game_test.go index ec60e3e..59d91f9 100644 --- a/game_test.go +++ b/game_test.go @@ -280,6 +280,17 @@ func TestMoveHistory(t *testing.T) { } } +func TestMoveHistoryProgrammatic(t *testing.T) { + game := NewGame() + game.MoveStr("e4") + game.MoveStr("e5") + game.Resign(Black) + history := game.MoveHistory() // Panics here + if len(history) != 2 { + t.Fatal("Didn't retrieve full history") + } +} + func BenchmarkStalemateStatus(b *testing.B) { fenStr := "k1K5/8/8/8/8/8/8/1Q6 w - - 0 1" fen, err := FEN(fenStr) diff --git a/pgn.go b/pgn.go index c14b9b7..416eef3 100644 --- a/pgn.go +++ b/pgn.go @@ -180,6 +180,7 @@ func decodePGN(pgn string) (*Game, error) { if err := g.Move(m); err != nil { return nil, fmt.Errorf("chess: pgn invalid move error %s on move %d", err.Error(), g.Position().moveCount) } + g.comments = g.comments[:len(g.comments)-1] g.comments = append(g.comments, move.Comments) } g.outcome = outcome