python - 当分数类似于“-M8”时,python-chess 返回“none”
问题描述
我将 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))
解决方案
推荐阅读
- wordpress - 通过编码从页面中获取 WordPress Shortcode atts 值
- github - 如果通过 Github Web GUI 编辑,请检查文件的语法
- dynamics-crm - Power Apps 模型驱动应用程序/Dynamics 365 中嵌入的 Power Automate (Microsoft Flow) 未触发
- xsd - 如何修复此 XML 架构?
- flutter - 如何从资产中制作带有图片的图标?
- c++11 - 模板复制构造函数是否覆盖默认复制构造函数?
- powershell - Powershell 真的需要 HTML 扩展并且不能与 HTM 一起使用吗?
- dc.js - dc-js 中的 2 行 LineGraph
- sql - 从 SQLite 中的 SQL 查询结果中删除重复项
- sql - 如何在SQL中加入2个没有关系的表