def analyze_game(game, game_pgn, thinktime, stockfish_path): game_analysis = {} game_analysis['white'] = game_pgn.white game_analysis['black'] = game_pgn.black game_analysis['event'] = game.event game_analysis['date'] = game.date game_analysis['analysis_date'] = str(datetime.now()) game_analysis['positions'] = [] engine = Engine(stockfish_path) moves = [] for i in range(len(game.moves)): move_pgn = game_pgn.moves[i] white_to_move = i % 2 == 0 move_str = str((i + 2) // 2) if white_to_move: move_str = move_str + "." else: move_str = move_str + "..." print("Analyzing move " + move_str) position = { 'move_number': move_str, 'side': 'white' if white_to_move else 'black', 'move': move_pgn, 'details': engine.go_time(thinktime), } move = game.moves[i] moves.append(move) engine.setposition(moves) position['fen'] = engine.fen() game_analysis['positions'].append(position) engine.terminate() return game_analysis
# -*- coding: utf-8 -*- """ Created on Wed May 27 03:05:42 2020 @author: user """ from pystockfish import Engine deepthinker = Engine(depth=15) deepthinker.setposition(['e2e4', 'e7e5']) deepthinker.bestmove()