Using python chess, I would like to be able to list specific moves from a pgn string. For instance, in this string:
- c4 e5 2. g3 c6 ( 2... d5 3. cxd5 ) 3. Nf3 e4 4. Nd4 d5 5. cxd5 Qxd5 6. Nc2 ( 6. e3 ) 6... Nf6 7. Nc3 Qe5 8. Bg2 Na6 9. O-O Be7 10. Ne3 O-O 11. a3 Re8 ( 11... Nc7 ) 12. b4 Ng4 13. Bb2 Qh5 14. h4 Bf6 ( 14... Nxe3 15. dxe3 f5 16. Qb3+ Kh8 17. Na4 Qg6 18. Qc2 Nc7 19. Bd4 ) 15. Qc2 Nxe3 16. dxe3 Bf5 17. Na4 Bxb2 ( 17... Bxh4 18. gxh4 ) 18. Nxb2 ( 18. Qxb2 Nc7 ) 18... Nc7 19. Nc4 Re6 20. Rfd1 Nd5 21. Rd4 ( 21. b5 g5 ) 21... h6 ( 21... g5 ) 22. Qd2 ( 22. Rad1 g5 ) 22... Rae8 23. Kh2 ( 23. Rxd5 ) 23... Bg4 24. Na5 ( 24. Re1 g5 ) 24... Rf6 25. Kg1 g5 26. Nxb7 ( 26. Qb2 Ree6 27. Bxe4 gxh4 28. Bf3 Rg6 29. Rxg4 Rxg4 30. Bxg4 Qxg4 ) 26... gxh4 27. Nc5 h3 28. Rxe4 ( 28. Nxe4 Rfe6 ) 28... hxg2 29. Rxe8+ Kg7 30. f4 Qh1+ 31. Kf2 Qxa1 32. Kxg2 Bh3+ 0-1
I would like the first 5 moves and their variations (or a different set for example moves 6 to 10):
- c4 e5 2. g3 c6 ( 2... d5 3. cxd5 ) 3. Nf3 e4 4. Nd4 d5 5. cxd5 Qxd5
The string is generated using a command like this:
exporter = chess.pgn.StringExporter(headers=False, variations=False, comments=False)
pgn_string = games1.accept(exporter)
print(pgn_string)