本文整理汇总了Python中pychess.Utils.GameModel.GameModel.tags["FEN"]方法的典型用法代码示例。如果您正苦于以下问题:Python GameModel.tags["FEN"]方法的具体用法?Python GameModel.tags["FEN"]怎么用?Python GameModel.tags["FEN"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.GameModel.GameModel
的用法示例。
在下文中一共展示了GameModel.tags["FEN"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import tags["FEN"] [as 别名]
def loadToModel(self, rec, position, model=None):
if not model:
model = GameModel()
if self.fen_is_string:
rec = self.games[0]
if isinstance(rec, dict) and "Variant" in rec:
model.variant = FischerandomBoard
fen = self.games[0]["FEN"]
try:
board = model.variant(setup=fen)
model.tags["FEN"] = fen
except SyntaxError as err:
board = model.variant()
raise LoadingError(
_("The game can't be loaded, because of an error parsing FEN"),
err.args[0])
model.boards = [board]
model.variations = [model.boards]
model.moves = []
if model.status == WAITING_TO_START:
status, reason = getStatus(model.boards[-1])
if status in (BLACKWON, WHITEWON, DRAW):
model.status, model.reason = status, reason
return model
示例2: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import tags["FEN"] [as 别名]
def loadToModel(self, rec, position=-1, model=None):
""" Parse game text and load game record header tags to a GameModel object """
if not model:
model = GameModel()
if self.pgn_is_string:
rec = self.games[0]
# Load mandatory tags
for tag in mandatory_tags:
model.tags[tag] = rec[tag]
# Load other tags
for tag in ('WhiteElo', 'BlackElo', 'ECO', 'TimeControl', 'Annotator'):
model.tags[tag] = rec[tag]
if self.pgn_is_string:
for tag in rec:
if isinstance(rec[tag], str) and rec[tag]:
model.tags[tag] = rec[tag]
else:
model.info = self.tag_database.get_info(rec)
extra_tags = self.tag_database.get_exta_tags(rec)
for et in extra_tags:
model.tags[et['tag_name']] = et['tag_value']
if self.pgn_is_string:
variant = rec["Variant"].capitalize()
else:
variant = self.get_variant(rec)
if model.tags['TimeControl']:
tc = parseTimeControlTag(model.tags['TimeControl'])
if tc is not None:
secs, gain, moves = tc
model.timed = True
model.timemodel.secs = secs
model.timemodel.gain = gain
model.timemodel.minutes = secs / 60
model.timemodel.moves = moves
for tag, color in (('WhiteClock', WHITE), ('BlackClock', BLACK)):
if tag in model.tags:
try:
millisec = parseClockTimeTag(model.tags[tag])
# We need to fix when FICS reports negative clock time like this
# [TimeControl "180+0"]
# [WhiteClock "0:00:15.867"]
# [BlackClock "23:59:58.820"]
start_sec = (
millisec - 24 * 60 * 60 * 1000
) / 1000. if millisec > 23 * 60 * 60 * 1000 else millisec / 1000.
model.timemodel.intervals[color][0] = start_sec
except ValueError:
raise LoadingError(
"Error parsing '%s'" % tag)
fenstr = rec["FEN"]
if variant:
if variant not in name2variant:
raise LoadingError("Unknown variant %s" % variant)
model.tags["Variant"] = variant
# Fixes for some non statndard Chess960 .pgn
if (fenstr is not None) and variant == "Fischerandom":
parts = fenstr.split()
parts[0] = parts[0].replace(".", "/").replace("0", "")
if len(parts) == 1:
parts.append("w")
parts.append("-")
parts.append("-")
fenstr = " ".join(parts)
model.variant = name2variant[variant]
board = LBoard(model.variant.variant)
else:
model.variant = NormalBoard
board = LBoard()
if fenstr:
try:
board.applyFen(fenstr)
model.tags["FEN"] = fenstr
except SyntaxError as err:
board.applyFen(FEN_EMPTY)
raise LoadingError(
_("The game can't be loaded, because of an error parsing FEN"),
err.args[0])
else:
board.applyFen(FEN_START)
boards = [board]
del model.moves[:]
del model.variations[:]
self.error = None
movetext = self.get_movetext(rec)
boards = self.parse_movetext(movetext, boards[0], position)
#.........这里部分代码省略.........