1

我将 python 3.6 与 Jupyter 和 Anaconda 一起使用。该脚本从 PGN 文件中逐个移动,并返回一个分数。这很好用。

当返回的分数是“-M8”时,问题就来了,这意味着黑棋可以在8步内将死。

但是下面一行:

(handler.info["score"][1].cp)

按预期返回“none”而不是“-M8”。

脚本:

import chess
import chess.uci
import chess.pgn
import sys

with open('E:\PGN Files\Fischer.pgn') as f:


    handler = chess.uci.InfoHandler()
    engine = chess.uci.popen_engine('C:\Program Files (x86)\Arena\Engines\stockfish_9_x64.exe') #give correct address of your engine here
    engine.info_handlers.append(handler)

    for number in range(10):
        game = chess.pgn.read_game(f)
        m=0
        while not game.is_end():
            m=m+1
            node = game.variations[0]
            board = game.board() 

            game = node         

            engine.position(board)

            #Set your evaluation time, in ms:
            evaltime = 5000 #so 5 seconds
            evaluation = engine.go(movetime=evaltime)

            score =(handler.info["score"][1].cp)
            print(str(score))
4

0 回答 0