PGN with scores like this:
- e4 {+0.42/27 1.6s} e5 {-0.21/26 5.4s}
- Nf3 {+0.34/22 0.94s} Nc6 {-0.16/19 0.37s}
- Bb5 {+0.35/27 2.1s} Nf6 {-0.19/26 0.80s}
- O-O {+0.33/22 0.56s} Nxe4 {-0.16/26 0.92s}
- Re1 {+0.29/27 1.0s} Nd6 {-0.19/24 0.66s}
- Nxe5 {+0.32/24 0.59s, No result} *
my code is as follows:
self.move_stack = []
with open(file_path) as f:
game = chess.pgn.read_game(f)
if game:
self.board = game.board()
self.move_stack = list(game.mainline_moves())
It can extract moves, but I don’t know how to extract the scores like 0,42.
I have read the documents about how to parsing PGN file. https://python-chess.readthedocs.io/en/latest/pgn.html. It says eval() should work. But I tried with game.eval() and game.variations[0].eval(), both of them didn’t work.
game.variations[0].comment can get the whole comment(+0.42/27 1.6s). I just want the first part 0.42.
finally, I managed to use a stupid way to get the scores.
i=0
for x in move_comment:
if x!= "/":
i=i+1
else:
break
original_score=move_comment[0:i]
The_original_scores.append(float(original_score))
There must be a simple way to do it.
user28471654 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.