问题描述
我正在尝试使用python stockfish库获得一系列fen职位的评估。当解决方案与x配合使用时,我的代码将快速运行。当解决方案是x厘泊时,它将运行很长时间。我如何获得干鱼以限制其思考评估所需的时间?这是我的代码:
fish = Stockfish()
evals = []
fen = 'r1bqk2r/pp1pbppp/2n1pn2/2p5/2B1N3/4PN2/PPPP1PPP/R1BQ1RK1 b kq - 1 1'
fish.set_fen_position(fen)
fish.get_evaluation()
解决方法
您可以使用 python-chess
库 ($ pip instep python-chess
) 并简单地执行此操作:
import chess
import chess.engine
engine = chess.engine.SimpleEngine.popen_uci("your/stockfish/path/here.exe")
fen = 'r1bqk2r/pp1pbppp/2n1pn2/2p5/2B1N3/4PN2/PPPP1PPP/R1BQ1RK1 b kq - 1 1'
board = chess.Board(fen)
evaluation = chess.engine.Limit(time=1))['score']
print(evaluation)