def export(self, pgn_headers=None) -> Game: """ pgn_headers - PGN headers to include in the exported PGN """ fen = self.puzzle.initial_board.fen() board = chess.Board(fen) game = Game().from_board(board) game_node = game game_node.comment = "score: %s -> %s" % (_score_to_str( self.puzzle.initial_score), _score_to_str(self.puzzle.final_score)) comment = self._candidate_moves_annotations(self.puzzle.analyzed_moves) for position in self.puzzle.positions: game_node = game_node.add_variation( chess.Move.from_uci(position.initial_move.uci())) if comment: game_node.comment = comment comment = self._candidate_moves_annotations( position.candidate_moves) if pgn_headers: for h in pgn_headers: if h == "FEN": continue game.headers[h] = pgn_headers[h] game.headers['PuzzleCategory'] = self.puzzle.category() puzzle_winner = self.puzzle.winner() if puzzle_winner: game.headers['PuzzleWinner'] = puzzle_winner game.headers['PuzzleEngine'] = AnalysisEngine.name() game.headers['PuzzleMakerVersion'] = __version__ return game
if settings.quiet: configure_logging(level=logging.INFO) else: configure_logging(level=logging.DEBUG) def print_puzzle_pgn(puzzle, pgn_headers=None): puzzle_pgn = puzzle.to_pgn(pgn_headers=pgn_headers) log(Color.MAGENTA, "NEW PUZZLE GENERATED\n") print(Color.CYAN + puzzle_pgn + "\n\n" + Color.ENDC) # load a FEN and try to create a puzzle from it if settings.fen: log(Color.DIM, AnalysisEngine.name()) puzzle = Puzzle(Board(settings.fen)) puzzle.generate(depth=settings.search_depth) if puzzle.is_complete(): print_puzzle_pgn(puzzle) engine.quit() exit(0) # load games from a PGN and scan them for puzzles n_positions = 0 # number of positions considered n_puzzles = 0 # number of puzzles generated game_id = 0 pgn = open(settings.pgn, "r") while game_id < settings.start_index: