You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Output individual FEN strings for each position from a chosen perspective, including variations. The FEN position should be before the opposite color made their move.
Include a move list after the FEN string (the first move would be the opposite color, and the second move would be the move from the chosen perspective).
If any moves had annotations (comments/[%csl ...]/[%cal ...]) those should be preserved in the move list as well.
Example:
With the following PGN as input, and black as the chosen perspective…
How can I include not only moves but also the move numbers and comments/annotations from the PGN? If anyone could provide some pointers that would be great.
importchessimportchess.pgnpgn_file='/path'repertoire_color='black'ifrepertoire_color=='black':
setup_positions=chess.WHITE# FEN positions will be before opponents moveelifrepertoire_color=='white':
setup_positions=chess.BLACK# FEN positions will be before opponents movewithopen(pgn_file) aspgn:
parsed_pgn=chess.pgn.read_game(pgn)
defextract_positions(node, color):
ifnode.board().turn==color:
fen=node.board().fen()
ifnode.variations:
# Get opponent moveforvariationinnode.variations:
opponent_move=variation.move# Convert move to algebraic notationalgebraic_opponent_move=node.board().san(opponent_move)
ifvariation.variations:
# For each found move, check if there's a response in the repertoireresponse_move=variation.variations[0].moveifresponse_move:
# Convert move to algebraic notationalgebraic_response_move=variation.board().san(response_move)
# Print the position and move pairprint(f'[FEN "{fen}"]\n{algebraic_opponent_move}{algebraic_response_move}\n')
# Recursively process nodes to extract all positions (both main line and sidelines)forvariationinnode.variations:
extract_positions(variation, color)
extract_positions(parsed_pgn, setup_positions)
I would like to achieve the following:
[%csl ...]
/[%cal ...]
) those should be preserved in the move list as well.Example:
With the following PGN as input, and black as the chosen perspective…
…the desired output would be:
I hope that all made sense.
Is this possible? I would be grateful for any pointers on how to achieve it.
The text was updated successfully, but these errors were encountered: