限制stockfish评估时间

2024-05-13 22:27:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用Python stockfish库获取一系列fen位置的评估。当解决方案在x中匹配时,我的代码运行得很快。当溶液为x厘米时,它会运行很长时间。如何让stockfish限制思考评估的时间?这是我的密码:

fish = Stockfish()
evals = []
fen = 'r1bqk2r/pp1pbppp/2n1pn2/2p5/2B1N3/4PN2/PPPP1PPP/R1BQ1RK1 b kq - 1 1'
fish.set_fen_position(fen)
fish.get_evaluation()

Tags: 密码时间解决方案fish溶液stockfish代码运行fen
1条回答
网友
1楼 · 发布于 2024-05-13 22:27:09

您可以使用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)

相关问题 更多 >