How to cut these pgn games.

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to cut these pgn games.

Post by Ferdy »

Jonathan003 wrote: Sun Mar 17, 2019 6:10 pm Here are some exemples where it goes wrong.

pgn: my games.pgn

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[ECO "A58"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[PlyCount "39"]

{[%evp 18,27,45,34,34,34,40,34,48,48,54,54]} 1. d4 Nf6 2. c4 c5 3. d5 b5 4.
cxb5 a6 5. bxa6 Bxa6 6. Nc3 d6 7. g3 g6 8. Bg2 Bg7 9. Nf3 Nbd7 10. Rb1 {
White is slightly better.} Nb6 {[%emt 0:00:05] A8: Benko/Volga Gambit: Lines
with 5 bxa6} 11. a4 O-O 12. O-O Ra7 13. b3 Qa8 {[%cal Rf6d5]} 14. Nh4 {
Predecessor:} Rb8 $146 15. Bb2 Nbd7 16. Ba1 Ne5 17. Qc2 Rab7 18. Rfd1 Qa7 19.
Bf1 Ne8 20. Ne4 {1-0 (44) Piket,J (2609)-Topalov,V (2700) Wijk aan Zee 1999} *
This one

Code: Select all

[%emt 0:00:05]
This is emt = elapsed move time, probably what your saw in chessbase gui.

The script can handle this because it is enclosed in [ ... ].
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to cut these pgn games.

Post by Ferdy »

Jonathan003 wrote: Sun Mar 17, 2019 6:10 pm Here are some exemples where it goes wrong.

Here is the output. pgn output_mygames.pgn

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]

*
Chessbase pgn output file is problematic. Run your pgn file thru pgn-extract.

Command line:

Code: Select all

pgn-extract --output clean_mygames.pgn mygames.pgn
Then use that clean_mygames.pgn to run in pgn_modifier.py.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to cut these pgn games.

Post by Ferdy »

Jonathan003 wrote: Sun Mar 17, 2019 6:10 pm
[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[ECO "A70"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[PlyCount "27"]

{[%evp 13,27,45,45,16,26,26,31,31,31,31,42,42,46,46,46,46]} 1. d4 Nf6 2. c4 c5
3. d5 e6 4. Nc3 d6 5. Nf3 exd5 6. cxd5 g6 7. e4 a6 8. Qe2 {[%emt 0:00:07]
White wants to play e5. A0: Modern Benoni: 6 e4 g6 7 Nf3} Bg4 9. e5 dxe5 10.
Qxe5+ {White is slightly better.} Qe7 11. Qxe7+ Bxe7 12. Ne5 Nbd7 13. Nxg4 Nxg4
14. h3 $146 ({Predecessor:} 14. Bf4 Nge5 15. O-O-O Bd6 {1-0 (61) Carlsen,M
(2770)-Ivanchuk,V (2746) Leon 2009}) *
On that do you also want to remove the comment before the A0?.
White wants to play e5.
The output is currently like this.

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[ECO "A70"]
[PlyCount "27"]

1. d4 Nf6 2. c4 c5 3. d5 e6 4. Nc3 d6 5. Nf3 exd5 6. cxd5 g6 7. e4 a6 8. Qe2 { White wants to play e5. A0: Modern Benoni: 6 e4 g6 7 Nf3 } *
Jonathan003
Posts: 239
Joined: Fri Jul 06, 2018 4:23 pm
Full name: Jonathan Cremers

Re: How to cut these pgn games.

Post by Jonathan003 »

On that do you also want to remove the comment before the A0?.
Yes I would like to remove also the comment before the eco code. I run the tactical analysis with the setting to 0, to make it fast. So the analysis is not trustworthy. Can you please make it also possible to not remove the remaining moves? If I want to delete the remaining moves I can do it myself by placing a * after the comment with the opening name.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to cut these pgn games.

Post by Ferdy »

Jonathan003 wrote: Sun Mar 17, 2019 6:44 pm Yes I would like to remove also the comment before the eco code.
Will try that.
I run the tactical analysis with the setting to 0, to make it fast. So the analysis is not trustworthy. Can you please make it also possible to not remove the remaining moves? If I want to delete the remaining moves I can do it myself by placing a * after the comment with the opening name.
Can you give an example? Want to see this remaining moves in pgn.

You already have chessbase. May I know what do you want to achieve with all of these? :)
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to cut these pgn games.

Post by Ferdy »

Jonathan003 wrote: Sun Mar 17, 2019 6:44 pm
On that do you also want to remove the comment before the A0?.
Yes I would like to remove also the comment before the eco code.
This code will remove any comments to the left of ECO.

Code: Select all

"""
pgn_modifier.py

Read pgn and remove some comments and cut the move length at specific move.

Requirements:
    python 3
    python-chess v0.26.0 and up
    
Dev log:
    v0.3
    * Remove all text in the move comment before the ECO code. Example,
    { White is slightly better. A67: Modern Benoni: Taimanov Variation }
    Remove "White is slightly better."

    v0.2
    * Read ECO letter + single digit, that is A1, B2 etc.
    * Prompt user of pgn file and the output is 'output_[user pgn filename].

"""


import os
import chess.pgn

    
def main(): 
    pgnfn = input('enter pgn filename? ')
    output_pgnfn = 'output_' + pgnfn
    
    # Delete existing output_mygames.pgn
    if os.path.isfile(output_pgnfn):
        os.remove(output_pgnfn)
    
    # Build ECO, used to cut the game length
    ECO = []
    for i in range(100):
        # A00 to E99, A0, A1 ... A9 ... E9
        if i < 10:
            aecos = 'A{}'.format(i)
            becos = 'B{}'.format(i)
            cecos = 'C{}'.format(i)
            decos = 'D{}'.format(i)
            eecos = 'E{}'.format(i)
        
        aeco = 'A{:02d}'.format(i)
        beco = 'B{:02d}'.format(i)
        ceco = 'C{:02d}'.format(i)
        deco = 'D{:02d}'.format(i)
        eeco = 'E{:02d}'.format(i)
        
        ECO.append(aecos)
        ECO.append(becos)
        ECO.append(cecos)
        ECO.append(decos)
        ECO.append(eecos)
        
        ECO.append(aeco)
        ECO.append(beco)
        ECO.append(ceco)
        ECO.append(deco)
        ECO.append(eeco)
    
    gcnt = 0
    
    # Parse games in pgn file
    with open(pgnfn, 'r') as pgn:
        game = chess.pgn.read_game(pgn)        
        while game:
            gcnt += 1
            
            # Console progress
            print('game: {}'.format(gcnt))
            
            mygame = chess.pgn.Game()
            mynode = mygame
            
            # Copy orig game header to our saved game header
            for k, v in game.headers.items():
                mygame.headers[k] = v
            
            for node in game.mainline():
                game_move = node.move                 
                move_comment = node.comment
                
                # Modify move comment, remove comments enclosed in [ ]
                # [%emt 0:00:05] A87: Dutch Defence: Leningrad System: Nf3
                if '[' in move_comment and ']' in move_comment:              
                    move_comment = move_comment.split(']')[1].strip()
                
                mynode = mynode.add_main_variation(game_move)
                
                # Check the move comment where we can cut the game length
                # Also remove comments before ECO if there is ECO
                is_foundvalidcomment = False
                newcom = move_comment
                for c in ECO:
                    if c in move_comment:
                        is_foundvalidcomment = True
                        
                        # Remove comments to the left of ECO
                        # White is slightly better. A67: Modern Benoni: Taimanov Variation
                        eco_com = move_comment.split(':')[0].split()[-1].strip()
                        newcom = eco_com + ':' + move_comment.split(eco_com + ':')[1]
                        break
                    
                if is_foundvalidcomment:
                    mynode.comment = newcom  
                
                # Don't copy other moves we stop here
                if is_foundvalidcomment:
                    break
            
            # Print to output file
            with open(output_pgnfn, 'a') as w:
                w.write('{}\n\n'.format(mygame))
            
            # Print to console
            print(mygame)
            print()
            
            # Read another game
            game = chess.pgn.read_game(pgn)


if __name__ == '__main__':
    main()
Jonathan003
Posts: 239
Joined: Fri Jul 06, 2018 4:23 pm
Full name: Jonathan Cremers

Re: How to cut these pgn games.

Post by Jonathan003 »

Can you give an example? Want to see this remaining moves in pgn.

You already have chessbase. May I know what do you want to achieve with all of these? :)
I'm very busy with finding best ways to make and train repertoires. I divide the repertoires in small pgn files ordered by opening. Than I make repertoires in chesstempo opening trainer beta. In chesstempo opening trainer beta it is possible to set bookmarks. That's why I want to use these annotations with the opening names. I first want to cut the repertoires eco related length. I want it eco related lengt, and not just cut the games after 12 ply's or so. Later I want to train the repertoires more ply's deep. That's why I also want an option to keep the remaining moves after the annotations with the opening name.

I will try the latest codes you send with bigger pgn files to see the results. Thanks already for all of your effort!
Jonathan003
Posts: 239
Joined: Fri Jul 06, 2018 4:23 pm
Full name: Jonathan Cremers

Re: How to cut these pgn games.

Post by Jonathan003 »

There where 4 games out of the 345 games that did not get an annotation with the opening name for the white repertoire.
And there where 10 games out of the 839 games that did not get an annotation with the opening name for the black repertoire.
To invest it I did the following. I converted the repertoires to cbh in chessbase 15. I created a search booster. And I searched for all games with a tex annotation, and deleted these. So the remaining games where the games with no annotation with the eco code and opening names. I called these invest_white.pgn and invest_black.pgn
I repeated the process on these files. I first created tactical analysis. And then I run the pgn modifier again. Strange enough there are now less games with no opening annotation. But there is still 1 for output_invest_white.pgn and 4 for output_invest_black.pgn
I post the results here.


invest_white.pgn


[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[ECO "D10"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[PlyCount "27"]

{[%evp 9,27,3,115,75,60,36,82,72,62,52,41,39,120,-2,131,-20,19,94,83,42]} 1. d4
d5 2. c4 c6 3. Nc3 {[%cal Bb1c3,Bc3e4,Be4d2][%mdl 32]} dxc4 4. e3 b5 {[%cal
Bb7b5,Bb5b4][%mdl 32]} 5. a4 b4 6. Ne4 {D10: Slav Defence: 3 cxd5 (without
early Nf3) and 3 Nc3} Qd5 7. Nd2 c3 8. bxc3 bxc3 9. Nb1 Qa5 {[#] Hoping for ...
c2+.} 10. Qc2 e5 11. Nf3 Na6 12. Nxe5 Nb4 $1 {[%cal Rb4c2]} 13. Qb3 Be6 14. Bc4
$146 {Accuracy: White = 11%, Black = 29%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[ECO "C06"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[PlyCount "45"]

{[%evp 27,45,86,96,62,109,51,108,65,98,42,149,50,131,116,134,119,158,131,189,
131]} 1. d4 $146 e6 2. e4 d5 3. Nd2 Nf6 4. e5 Nfd7 5. c3 c5 6. Bd3 Nc6 7. Ngf3
Qb6 8. O-O cxd4 9. cxd4 Nxd4 10. Nxd4 Qxd4 11. Nf3 Qb6 12. Qa4 Qb4 13. Qc2 Qc5
14. Qe2 Qb6 15. a3 {[%mdl 1024] White has strong compensation. C06: French
Tarrasch: 3...Nf6 4 e5 Nfd7 5 Bd3 main lines} Be7 16. Be3 Qd8 17. Rac1 {
White is better.} O-O 18. Rc3 f5 19. exf6 Bxf6 {[#] White must now prevent ...
e5.} 20. Bd4 $36 {[%mdl 2048] Keeping Black busy.} Bxd4 21. Nxd4 ({Much less
strong is} 21. Qxe6+ $6 Kh8 $14) 21... Nf6 22. Nxe6 Bxe6 23. Qxe6+ {Accuracy:
White = 7%, Black = 45%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[ECO "E62"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[PlyCount "37"]

{[%evp 17,37,72,119,70,130,49,78,62,119,91,152,63,188,112,203,173,325,153,171,
128,202,152]} 1. d4 $146 g6 2. Nf3 Nf6 3. g3 Bg7 4. Bg2 O-O 5. O-O d6 6. c4 Nc6
7. Nc3 e5 8. d5 Ne7 9. e4 c6 10. a4 {E62: King's Indian: Fianchetto: 6...c6
and Panno Variation (6...Nc6) without ...a6} Bg4 11. a5 cxd5 12. cxd5 {White
is better.} Qd7 13. Be3 Rfc8 14. Qa4 Ne8 15. Nd2 Qd8 16. Qb4 Nc7 17. Nc4 Na6
18. Qxb7 {[%mdl 64] [#] Double Attack} Rxc4 19. Qxa6 {Accuracy: White = 9%,
Black = 2%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[ECO "E62"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[PlyCount "37"]

{[%evp 17,37,83,139,56,113,71,80,66,137,74,155,63,184,114,219,198,300,178,192,
148,178,170]} 1. d4 $146 Nf6 2. c4 g6 3. Nf3 Bg7 4. g3 O-O 5. Bg2 d6 6. O-O Nc6
7. Nc3 e5 8. d5 Ne7 9. e4 c6 10. a4 {[%cal Ba2a4,Ba4a5][%mdl 32] E62: King's
Indian: Fianchetto: 6...c6 and Panno Variation (6...Nc6) without ...a6} Bg4 11.
a5 cxd5 12. cxd5 {White is better.} Qd7 13. Be3 Rfc8 14. Qa4 Ne8 15. Nd2 Qd8
16. Qb4 Nc7 17. Nc4 Na6 18. Qxb7 {[%mdl 64] [#] Double Attack} Rxc4 19. Qxa6 {
Accuracy: White = 3%, Black = 2%.} *


output_invest_white.pgn


[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]

1. d4 d5 2. c4 c6 3. Nc3 dxc4 4. e3 b5 5. a4 b4 6. Ne4 { D10: Slav Defence: 3 cxd5 (without
early Nf3) and 3 Nc3 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[ECO "C06"]
[PlyCount "45"]

1. d4 e6 2. e4 d5 3. Nd2 Nf6 4. e5 Nfd7 5. c3 c5 6. Bd3 Nc6 7. Ngf3 Qb6 8. O-O cxd4 9. cxd4 Nxd4 10. Nxd4 Qxd4 11. Nf3 Qb6 12. Qa4 Qb4 13. Qc2 Qc5 14. Qe2 Qb6 15. a3 { C06: French
Tarrasch: 3...Nf6 4 e5 Nfd7 5 Bd3 main lines } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[ECO "E62"]
[PlyCount "37"]

1. d4 g6 2. Nf3 Nf6 3. g3 Bg7 4. Bg2 O-O 5. O-O d6 6. c4 Nc6 7. Nc3 e5 8. d5 Ne7 9. e4 c6 10. a4 { E62: King's Indian: Fianchetto: 6...c6
and Panno Variation (6...Nc6) without ...a6 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "My White Opening"]
[Black "Black Opening"]
[Result "*"]
[Annotator "Tactical Analysis 2.10 (6s)"]
[ECO "E62"]
[PlyCount "37"]

1. d4 Nf6 2. c4 g6 3. Nf3 Bg7 4. g3 O-O 5. Bg2 d6 6. O-O Nc6 7. Nc3 e5 8. d5 Ne7 9. e4 c6 10. a4 Bg4 11. a5 cxd5 12. cxd5 Qd7 13. Be3 Rfc8 14. Qa4 Ne8 15. Nd2 Qd8 16. Qb4 Nc7 17. Nc4 Na6 18. Qxb7 Rxc4 19. Qxa6 *

invest_black.pgn

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "28"]

{[%evp 12,28,-46,-112,238,-54,-47,-59,4,-35,17,-5,19,13,43,-31,54,-8,50]} 1.
Nf3 Nf6 2. c4 e6 3. Nc3 Bb4 4. d4 b6 5. Bg5 Bb7 6. Nd2 h6 7. Bh4 e5 $2 {
[%mdl 8192] [#] E13: Queen's Indian/Nimzo-Indian hybrid: 4 Nc3 Bb7 5 Bg5 h6 6
Bh4 Bb4} (7... O-O $17 {keeps the pressure on.}) (7... Qe7 8. Qc2 c5 9. a3 Bxc3
10. Qxc3 cxd4 11. Qxd4 Nc6 12. Qc3 Rc8 13. e3 O-O 14. Rd1 d5 15. Bxf6 gxf6 16.
cxd5 {0-1 (31) Jobava,B (2701)-Carlsen,M (2838) chess.com INT 2017}) 8. d5 $2 (
8. dxe5 $18 g5 9. Bg3 (9. exf6 Bxc3 10. bxc3 gxh4 $11) 9... Bxc3 10. bxc3) 8...
Bxc3 $15 9. bxc3 Na6 $146 {Black is slightly better.} ({Predecessor:} 9... d6
10. e3 g5 11. Bg3 Nbd7 12. Bd3 Nc5 13. Bf5 a5 14. O-O Qe7 15. f4 {1-0 (28)
Suleymanli,A (2313)-Abasov,N (2629) Baku 2018}) 10. f3 d6 11. e4 Nc5 12. Nb3
O-O 13. Be2 Bc8 14. O-O Bd7 {Accuracy: White = 15%, Black = 13%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

{[%evp 27,50,30,68,4,82,22,79,8,95,0,94,0,102,1,13,8,54,23,49,12,57,46,45,15,
76]} 1. Nf3 $146 Nf6 2. g3 g6 3. Bg2 Bg7 4. c4 O-O 5. d4 d6 6. Nc3 Nbd7 7. O-O
c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14.
Qxd3 Rfc8 15. Rb1 {E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3} Ne8 16. Be3 Qd8 17. Rfc1 {White is better.} a6 18. a4 Nf6 19. b3 Nh5 20.
Ne2 f5 21. Qd2 Qf8 22. Rxc8 Rxc8 23. Rc1 b5 24. a5 Nf6 25. f3 Nh5 {Accuracy:
White = 6%, Black = 5%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

{[%evp 27,50,11,70,19,74,15,71,3,72,0,80,12,92,29,30,15,75,32,32,29,71,28,37,
-10,75]} 1. Nf3 $146 Nf6 2. g3 g6 3. Bg2 Bg7 4. d4 O-O 5. c4 d6 6. Nc3 Nbd7 7.
O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14.
Qxd3 Rfc8 15. Rb1 {E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3} Ne8 16. Be3 Qd8 17. Rfc1 {White is better.} a6 18. a4 Nf6 19. b3 Nh5 20.
Ne2 f5 21. Qd2 Qf8 22. Rxc8 Rxc8 23. Rc1 b5 24. a5 Nf6 25. f3 Nh5 {Accuracy:
White = 16%, Black = 2%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

{[%evp 27,50,6,76,-1,57,24,80,0,75,-19,82,20,83,-6,35,23,74,7,21,9,56,15,43,
-13,71]} 1. Nf3 $146 Nf6 2. g3 g6 3. c4 Bg7 4. Bg2 O-O 5. d4 d6 6. Nc3 Nbd7 7.
O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14.
Qxd3 Rfc8 15. Rb1 {E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3} Ne8 16. Be3 Qd8 17. Rfc1 {White is better.} a6 18. a4 Nf6 19. b3 Nh5 20.
Ne2 f5 21. Qd2 Qf8 22. Rxc8 Rxc8 23. Rc1 b5 24. a5 Nf6 25. f3 Nh5 {Accuracy:
White = 14%, Black = 2%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

{[%evp 27,50,27,53,9,55,15,70,-5,79,-20,82,19,74,19,0,-63,82,22,29,4,64,1,25,
-5,84]} 1. Nf3 $146 Nf6 2. g3 g6 3. c4 Bg7 4. d4 O-O 5. Bg2 d6 6. Nc3 Nbd7 7.
O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14.
Qxd3 Rfc8 15. Rb1 {E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3} Ne8 16. Be3 Qd8 17. Rfc1 {White is slightly better.} a6 18. a4 Nf6 19. b3
Nh5 20. Ne2 f5 21. Qd2 Qf8 (21... f4 $5 22. gxf4 Qh4 $16) 22. Rxc8 Rxc8 23. Rc1
b5 24. a5 Nf6 25. f3 Nh5 {Accuracy: White = 15%, Black = 2%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

{[%evp 27,50,24,50,-1,49,10,70,-9,72,-21,92,19,78,19,34,15,62,30,48,31,52,0,32,
0,80]} 1. Nf3 $146 Nf6 2. g3 g6 3. d4 Bg7 4. Bg2 O-O 5. c4 d6 6. Nc3 Nbd7 7.
O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14.
Qxd3 Rfc8 15. Rb1 {E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3} Ne8 16. Be3 Qd8 17. Rfc1 {White is slightly better.} a6 18. a4 Nf6 19. b3
Nh5 20. Ne2 f5 21. Qd2 Qf8 22. Rxc8 Rxc8 23. Rc1 b5 24. a5 Nf6 25. f3 Nh5 {
Accuracy: White = 22%, Black = 0%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

{[%evp 27,50,13,39,-8,34,13,65,-2,78,-7,80,22,74,6,30,29,76,53,45,38,47,17,31,
-10,71]} 1. Nf3 $146 Nf6 2. g3 g6 3. d4 Bg7 4. c4 O-O 5. Bg2 d6 6. Nc3 Nbd7 7.
O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14.
Qxd3 Rfc8 15. Rb1 {E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3} Ne8 16. Be3 Qd8 17. Rfc1 {White is slightly better.} a6 18. a4 Nf6 19. b3
Nh5 20. Ne2 f5 21. Qd2 Qf8 22. Rxc8 Rxc8 23. Rc1 b5 24. a5 Nf6 25. f3 Nh5 {
Accuracy: White = 23%, Black = 9%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "32"]

{[%evp 15,32,50,72,43,60,-26,39,33,45,29,89,26,47,34,53,10,16,-39,87]} 1. c4
$146 e6 2. Nc3 d5 3. d4 Nf6 4. Nf3 Be7 5. Bf4 O-O 6. e3 Nbd7 7. c5 c6 8. Bd3 b6
9. b4 {[%cal Bb2b4,Bb4b5][%mdl 32] D37: Queen's Gambit Declined: 5 Bf4} a5 10.
b5 Bb7 11. cxb6 {White is slightly better.} Qxb6 12. O-O Rfc8 13. bxc6 Bxc6 14.
Rb1 Qd8 15. Qe2 Ne4 16. Rfc1 Ndf6 {Accuracy: White = 37%, Black = 15%.} (16...
Ba3 $5 {[%cal Ra3c1]} 17. Nxe4 dxe4 18. Rxc6 exd3 19. Rxc8 dxe2 20. Rxd8+ Rxd8
$14) *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "32"]

{[%evp 15,32,50,35,39,54,-84,27,11,52,38,83,24,54,29,60,0,32,-15,93]} 1. c4
$146 e6 2. Nf3 d5 3. d4 Nf6 4. Nc3 Be7 5. Bf4 O-O 6. e3 Nbd7 7. c5 c6 8. Bd3 b6
9. b4 {[%cal Bb2b4,Bb4b5][%mdl 32] D37: Queen's Gambit Declined: 5 Bf4} a5 10.
b5 Bb7 11. cxb6 {White has an edge.} Qxb6 12. O-O Rfc8 13. bxc6 Bxc6 14. Rb1
Qd8 15. Qe2 Ne4 16. Rfc1 Ndf6 {Accuracy: White = 21%, Black = 19%.} *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "28"]

{[%evp 12,28,-55,-95,200,-36,-30,-54,-6,-34,0,-15,0,-5,33,-28,25,-29,40]} 1. c4
e6 2. d4 Nf6 3. Nc3 Bb4 4. Bg5 b6 5. Nf3 Bb7 6. Nd2 h6 7. Bh4 e5 $2 {[%mdl
8192] [#] E13: Queen's Indian/Nimzo-Indian hybrid: 4 Nc3 Bb7 5 Bg5 h6 6 Bh4 Bb4
} (7... O-O $17 {stays on course.}) (7... Qe7 8. Qc2 c5 9. a3 Bxc3 10. Qxc3
cxd4 11. Qxd4 Nc6 12. Qc3 Rc8 13. e3 O-O 14. Rd1 d5 15. Bxf6 gxf6 16. cxd5 {
0-1 (31) Jobava,B (2701)-Carlsen,M (2838) chess.com INT 2017}) 8. d5 $2 ({
White has to play} 8. dxe5 $18 Bxc3 9. bxc3) 8... Bxc3 $15 9. bxc3 Na6 $146 {
Black is slightly better.} ({Predecessor:} 9... d6 10. e3 g5 11. Bg3 Nbd7 12.
Bd3 Nc5 13. Bf5 a5 14. O-O Qe7 15. f4 {1-0 (28) Suleymanli,A (2313)-Abasov,N
(2629) Baku 2018}) 10. f3 d6 11. e4 Nc5 12. Nb3 O-O 13. Be2 Bc8 14. O-O Bd7 {
Accuracy: White = 16%, Black = 13%.} *

output_invest_black.pgn

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]

1. Nf3 Nf6 2. c4 e6 3. Nc3 Bb4 4. d4 b6 5. Bg5 Bb7 6. Nd2 h6 7. Bh4 e5 8. d5 Bxc3 9. bxc3 Na6 10. f3 d6 11. e4 Nc5 12. Nb3 O-O 13. Be2 Bc8 14. O-O Bd7 *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

1. Nf3 Nf6 2. g3 g6 3. Bg2 Bg7 4. c4 O-O 5. d4 d6 6. Nc3 Nbd7 7. O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14. Qxd3 Rfc8 15. Rb1 { E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

1. Nf3 Nf6 2. g3 g6 3. Bg2 Bg7 4. d4 O-O 5. c4 d6 6. Nc3 Nbd7 7. O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14. Qxd3 Rfc8 15. Rb1 { E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

1. Nf3 Nf6 2. g3 g6 3. c4 Bg7 4. Bg2 O-O 5. d4 d6 6. Nc3 Nbd7 7. O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14. Qxd3 Rfc8 15. Rb1 { E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

1. Nf3 Nf6 2. g3 g6 3. c4 Bg7 4. d4 O-O 5. Bg2 d6 6. Nc3 Nbd7 7. O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14. Qxd3 Rfc8 15. Rb1 { E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

1. Nf3 Nf6 2. g3 g6 3. d4 Bg7 4. Bg2 O-O 5. c4 d6 6. Nc3 Nbd7 7. O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14. Qxd3 Rfc8 15. Rb1 { E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "50"]

1. Nf3 Nf6 2. g3 g6 3. d4 Bg7 4. c4 O-O 5. Bg2 d6 6. Nc3 Nbd7 7. O-O c6 8. e4 e5 9. h3 Qb6 10. d5 Nc5 11. Ne1 Bd7 12. Nd3 cxd5 13. cxd5 Nxd3 14. Qxd3 Rfc8 15. Rb1 { E69: King's Indian: Fianchetto: 6...Nbd7 7 0-0 e5 8 e4 c6 9
h3 } *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "32"]

1. c4 e6 2. Nc3 d5 3. d4 Nf6 4. Nf3 Be7 5. Bf4 O-O 6. e3 Nbd7 7. c5 c6 8. Bd3 b6 9. b4 a5 10. b5 Bb7 11. cxb6 Qxb6 12. O-O Rfc8 13. bxc6 Bxc6 14. Rb1 Qd8 15. Qe2 Ne4 16. Rfc1 Ndf6 *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "32"]

1. c4 e6 2. Nf3 d5 3. d4 Nf6 4. Nc3 Be7 5. Bf4 O-O 6. e3 Nbd7 7. c5 c6 8. Bd3 b6 9. b4 a5 10. b5 Bb7 11. cxb6 Qxb6 12. O-O Rfc8 13. bxc6 Bxc6 14. Rb1 Qd8 15. Qe2 Ne4 16. Rfc1 Ndf6 *

[Event "Chess Position Trainer"]
[Site "Chess Position Trainer"]
[Date "????.??.??"]
[Round "?"]
[White "White Opening"]
[Black "My Black Opening"]
[Result "*"]
[PlyCount "28"]

1. c4 e6 2. d4 Nf6 3. Nc3 Bb4 4. Bg5 b6 5. Nf3 Bb7 6. Nd2 h6 7. Bh4 e5 8. d5 Bxc3 9. bxc3 Na6 10. f3 d6 11. e4 Nc5 12. Nb3 O-O 13. Be2 Bc8 14. O-O Bd7 *
Jonathan003
Posts: 239
Joined: Fri Jul 06, 2018 4:23 pm
Full name: Jonathan Cremers

Re: How to cut these pgn games.

Post by Jonathan003 »

I'm happy with the results. If I also want the moves after the opening annotations I can do it by importing and exporting in chess position trainer. And for the few games without a opening annotation I can do it manually.
So thank you very much Ferdy for helping me out.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to cut these pgn games.

Post by Ferdy »

Jonathan003 wrote: Sun Mar 17, 2019 10:45 pm I'm happy with the results. If I also want the moves after the opening annotations I can do it by importing and exporting in chess position trainer. And for the few games without a opening annotation I can do it manually.
So thank you very much Ferdy for helping me out.
Parsing of whatever comments in the game is getting complicated now. I thought about a new method.

So is this your process?
1. You have a game, not necessarily a complete game. No comments, variations and NAGS etc.
2. Identify its ECO code and name/variation
3. Add the ECO code and name/variation as comment at appropriate move numbers.

If that is so I thought about doing like this.
1. Get the game
2. Get the eco.pgn (pgn-extract site has this, maybe same as what Dann has shared except Dann has the required pgn 7 tags which is better).
3. Read the game moves in reverse
4. If position in the game has a match to the position found in eco.pgn then insert that ECO and name/variation as comment to the last move in the game where the match is found.

An example game in the eco.pgn from Dann.

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]
[ECO "A49"]
[Variation "King's Indian: fianchetto (without c4)"]
[Comment "*pwo 1/02 book, footnote 32 (Nbd7) if 7.e4 then B07"]

1. d4 Nf6 2. Nf3 g6 3. g3 Bg7 4. Bg2 O-O 5. O-O d6 6. Nc3 Nbd7 *

Since parsing of moves in the input game is done in reverse, the first position that will match in the eco.pgn will be the one to use.