Skip to content

Atomic variant with chess960 PGN parsing #705

@fsmosca

Description

@fsmosca

Tried to parse an atomic variant with chess960 pgn file.

atomic_chess960.pgn

[White "?"]
[Black "?"]
[Result "*"]
[Variant "Atomic"]
[FEN "rkrbbnnq/pppppppp/8/8/8/8/PPPPPPPP/RKRBBNNQ w KQkq - 0 1"]

1. g3 d5 2. Nf3 e5 3. Ng5 Bxg5 4. Qf3 Ne6 5. Qa3 a5 6. d4 g6 7. c3 h5 8. h4 Qh6 9. Bd2 Qxd2 10. O-O-O *
def parse_game():
    pgn_file = 'atomic_chess960.pgn'

    with open(pgn_file) as file_handle:
        while True:
            game = chess.pgn.read_game(file_handle)
            if game is None:
                break

            print(f'game errors: {game.errors}\n')
            print(game)


if __name__ == "__main__":
    parse_game()

I got an error when using the latest versions chess==1.3.0 and python-chess==1.999

game errors: [ValueError("illegal san: 'O-O-O' in rkr1b1n1/1pp2p2/4n1p1/p2pp2p/3P3P/Q1P3P1/PP2PP2/RK3N2 w - - 0 10")]

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]
[FEN "rkrbbnnq/pppppppp/8/8/8/8/PPPPPPPP/RKRBBNNQ w KQkq - 0 1"]
[Variant "Atomic"]

1. g3 d5 2. Nf3 e5 3. Ng5 Bxg5 4. Qf3 Ne6 5. Qa3 a5 6. d4 g6 7. c3 h5 8. h4 Qh6 9. Bd2 Qxd2 *

If I use the older python-chess==0.31.1, there is no error.

game errors: []

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]
[FEN "rkrbbnnq/pppppppp/8/8/8/8/PPPPPPPP/RKRBBNNQ w KQkq - 0 1"]
[Variant "Atomic"]

1. g3 d5 2. Nf3 e5 3. Ng5 Bxg5 4. Qf3 Ne6 5. Qa3 a5 6. d4 g6 7. c3 h5 8. h4 Qh6 9. Bd2 Qxd2 10. O-O-O *

How to parse this kind pgn file with the latest version? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions