繁体   English   中英

无法在 python 棋中运行 stockfish

[英]Unable to run stockfish in python chess

def get_most_recent_game(username):
    data = get_player_game_archives(username).json
    url = data['archives'][-1]
    games = requests.get(url).json()
    game = games['games'][-1]
    #get game type(rapid...)
    gametype = game['time_class']
    print('PLAYERS -', gametype)
    #blacks stats
    black = game['black']
    blackusername = black['username']
    blackrating = black['rating']
    blackresult = black['result']
    print('Black)  Username:', blackusername, ' |  elo:', blackrating, ' |  result:', blackresult)
    #white stats
    white = game['white']
    whiteusername = white['username']
    whiterating = white['rating']
    whiteresult = white['result']
    print('White)  Username:', whiteusername, ' |  elo:', whiterating, ' |  result:', whiteresult)
    #get game moves
    gamepgn = game['pgn']
    pgnstring = str(gamepgn)
    pgn = StringIO(pgnstring)
    pgngame = chess.pgn.read_game(pgn)
    pgnmoves = pgngame.mainline_moves()
    board = pgngame.board()
    count = 0
    print("MOVES")
    for move in pgnmoves:
        count += 1
        print(board.san(move))
        board1 = board.push(move)
        engine = chess.engine.SimpleEngine.popen_uci(r"C:\Users\georg\VScode projects\chessanylizer\stockfish_15.1_win_x64_avx2")
        info = engine.analyse(board1, chess.engine.Limit(depth=20))
        print("Score:", info["score"])  
    #printer.pprint(game)

get_most_recent_game("gothamchess")

忽略大部分代码,错误出现在引擎变量的第 65 行,我尝试以管理员身份运行代码,我也尝试过更改鳕鱼的位置,我也尝试过在最后放置 .exe,但我保留了在此访问被拒绝错误上运行。

Traceback (most recent call last):
  File "c:\Users\georg\VScode projects\chessanylizer\chessanylizer.py", line 72, in <module>
    get_most_recent_game("gothamchess")
  File "c:\Users\georg\VScode projects\chessanylizer\chessanylizer.py", line 65, in get_most_recent_game
    engine = chess.engine.SimpleEngine.popen_uci(r"C:\Users\georg\VScode projects\chessanylizer\stockfish_15.1_win_x64_avx2")
  
PermissionError: [WinError 5] Access is denied

你走错了路径,你需要像这样指向.exe文件:

engine = chess.engine.SimpleEngine.popen_uci(r"C:\Users\xxxxx\Downloads\stockfish_14_win_x64\stockfish_14_win_x64_avx2.exe")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM