0

我正在尝试创建一个引擎,但我的评估功能很糟糕,所以我决定使用 stockfish 来为我评估它。

import chess
import chess.engine

def stockfish_evaluation(board, time_limit = 0.01):
    engine = chess.engine.SimpleEngine.popen_uci("stockfish/stockfish_10_x64")
    result = engine.play(board, chess.engine.Limit(time=time_limit))
    return result.info["score"]

board = chess.Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
result = stockfish_evaluation(board)
print(result)

但它打印出来:

KeyError: 'score'
4

1 回答 1

1

我认为您使用了错误的功能,应该engine.analyse不是engine.play

import chess
import chess.engine

def stockfish_evaluation(board, time_limit = 0.01):
    engine = chess.engine.SimpleEngine.popen_uci("stockfish_10_x64")
    result = engine.analyse(board, chess.engine.Limit(time=time_limit))
    return result['score']

board = chess.Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
result = stockfish_evaluation(board)
print(result)

#+58
于 2019-10-25T11:26:10.947 回答