-
objective code
result question thanks and best regards |
Beta Was this translation helpful? Give feedback.
Answered by
MarkZH
Aug 12, 2023
Replies: 1 comment
-
After reading the game with import chess
import chess.pgn
pgn_book = 'book.pgn'
with open(pgn_book, "w") as f:
f.write("""
[White "b"]
[Black "?"]
[Result "*"]
[FEN "8/1R3pk1/1P4p1/7p/7P/1r4P1/5PK1/8 w - - 0 1"]
[SourceVersionDate "2021.05.20"]
[SetUp "1"]
[Annotator "GM Petar G. Arnaudov"]
[PlyCount "25"]
1. Kf1 Rb2 2. Ke1 Kf6 3. f3 $1 Rb3 4. Kd2 Rxf3 $4 { this move loses } 5.
Rc7 $1 { [%cal Rc7c3] } (5. Kc2 Re3 $3 { everything else loses } 6. Rc7 Re8
7. b7 Rb8 $11) 5... Rb3 6. b7 Kf5 7. Kc2 Rb6 8. Rxf7+ Kg4 9. Rg7 $3 Kh3 10.
Kc3 Rb1 11. Rd7 $1 Kxg3 (11... Rb6 { is not saving the game too. } 12. Kc4
Kxg3 13. Rd3+ Kxh4 14. Rb3 Rxb7 15. Rxb7 $18) 12. Rd3+ Kxh4 (12... Kh2 13.
Rd2+ { [%cal Rd2b2] }) 13. Rd4+ $18 { [%cal Rd4b4] } *
""")
with open(pgn_book) as pgn:
first_game = chess.pgn.read_game(pgn)
print(first_game)
print("")
for node in first_game.mainline():
print(node.san())
if chess.pgn.NAG_BLUNDER in node.nags:
print(" blunder") |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sugizo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After reading the game with
first_game = chess.pgn.read_game(pgn)
, you'll want to iterate throughfirst_game.mainline()
. This will iterate throughChildNode
s that contain all of the move information. For example: