python国际象棋返回“;无”;当分数为“0”时-M8“;
我将Python3.6与Jupyter和Anaconda一起使用。 该脚本在国际象棋游戏中从PGN文件一步一步地移动,并返回一个分数。这很有效 当返回的分数为“-M8”时,问题就出现了,这意味着黑色可以在8步中将死 但是下面这句话:python国际象棋返回“;无”;当分数为“0”时-M8“;,python,anaconda,jupyter,python-chess,Python,Anaconda,Jupyter,Python Chess,我将Python3.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 F
(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))
open('E:\\PGN Files\\Fischer.PGN')
和Popen参数一样,不需要str(score)
,因为这正是print
所能做的。对不起,我的英语很糟糕,除此之外,你知道为什么引擎或python返回none而不是“-M8”?引擎在一个单独的进程中运行,您需要等待5秒或使用自定义处理程序。open('E:\\PGN Files\\Fischer.PGN')
和Popen参数一样,不需要str(score)
,因为这正是print
所能做的。对不起,关于我的英语,除此之外,您知道为什么引擎或python会返回none而不是“-M8”吗?发动机在单独的过程中运行,您需要等待5秒或使用自定义处理程序。