0

I need help to generate structured data from the PGN file as discs into a list in Python, or similar.

For example, say that I need to read this PGN file.

#######################################################

[Event "Teste_0-1500 c"] [Site "HIGGS-PC"] [Date "2021.03.13"] [Round "1"] [White "Cfish1200-modern"] [Black "Cmcchess 2.27"] [Result "1-0"] [ECO "B33"] [WhiteElo "1415"] [BlackElo "1330"] [Annotator "Boson,Higgs"] [PlyCount "160"] [EventDate "2021.??.??"]

  1. e4 ({Stockfish 13: (7453kN)} 1. d4 Nf6 2. c4 e6 3. Nf3 d5 4. Nc3 c6 5. e3 Nbd7 6. Be2 Bd6 7. O-O O-O 8. Qc2 e5 9. cxd5 cxd5 10. dxe5 Nxe5

#######################################################

I want to generate a data structure from the first PGN game to generate a list of discs.

[{'whiteplayer_name':'Cfish1200-modern', 'whiteplayer_Elo':1415, 'mainline_move_1_white':'e4', 'mainline_move_2_white':'Nf3', 'mainline_move_3_white':'d4',...,etc.}, {'Engine_1_name': 'Stockfish 13', 'move_white_suggested_by_engine_1_for_move_1':'d4', 'move_white_suggested_by_engine_1_for_move_2':'Nf3', 'move_white_suggested_by_engine_1_for_move_3':'Bb5', ... , etc., 'move_white_eval_by_engine_1_for_move_1':15, 'move_white_eval_by_engine_1_for_move_2':29, 'move_white_eval_by_engine_1_for_move_3':37}, {'Engine_2_name': 'Eman 6.94 64-bit SSE41 POPCNT', 'move_white_suggested_by_engine_2_for_move_1':'e4', 'move_white_suggested_by_engine_2_for_move_2':'Nf3', 'move_white_suggested_by_engine_2_for_move_3':'Bb5',...,etc., 'move_white_eval_by_engine_2_for_move_1':27, 'move_white_eval_by_engine_2_for_move_2':30, 'move_white_eval_by_engine_2_for_move_3':32,...,etc.}, etc.]

The same foes for the Black player and other such games. In total, I have around 600 games, each game analyzed by ~100 engines. Engines per game are not the same for all games and not the same number of engines per game. I tried to use chess.pgn, but I am a noob and could only extract the header data and mainline moves.

1
  • 2
    I’m voting to close this question because this question belongs to Stack Overflow. – Toby Harnish Apr 1 at 14:16
2

Python has a pgn parser as part of its chess library.

https://python-chess.readthedocs.io/en/latest/

4
  • Thanks. This is the first page I saw, but unfortunately it solves almost nothing. – Hick Nax Apr 1 at 4:22
  • why the reject? chess.stackexchange.com/review/suggested-edits/18841 – BCLC Apr 2 at 13:53
  • @BCLC "Any combination of chess and poker. In particular the most popular one currently is chokergame.com" was the suggested edit. Since this comment had nothing to do with the question, I rejected it. If this wasn't you suggested edit, I suggest that you take the issue with the site, as it's been acting peculiar lately. – Mike Jones Apr 3 at 18:19
  • 'Since this comment had nothing to do with the question' --> what question? – BCLC Apr 6 at 0:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.