本文整理汇总了Python中pychess.Utils.GameModel.GameModel.tags['Black']方法的典型用法代码示例。如果您正苦于以下问题:Python GameModel.tags['Black']方法的具体用法?Python GameModel.tags['Black']怎么用?Python GameModel.tags['Black']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.GameModel.GameModel
的用法示例。
在下文中一共展示了GameModel.tags['Black']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import tags['Black'] [as 别名]
def loadToModel(self, rec, position, model=None):
if not model:
model = GameModel()
model.tags['Event'] = rec["Event"]
model.tags['Site'] = rec["Site"]
model.tags['Date'] = self.get_date(rec)
model.tags['Round'] = ""
model.tags['White'] = "?"
model.tags['Black'] = "?"
model.tags['Termination'] = rec["Termination"]
fen = rec["FEN"]
model.boards = [model.variant(setup=fen)]
model.variations = [model.boards]
model.status = WAITING_TO_START
return model
示例2: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import tags['Black'] [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]
game_date = rec["Date"]
result = rec["Result"]
variant = rec["Variant"]
else:
game_date = self.get_date(rec)
result = reprResult[rec["Result"]]
variant = self.get_variant(rec)
# the seven mandatory PGN headers
model.tags['Event'] = rec["Event"]
model.tags['Site'] = rec["Site"]
model.tags['Date'] = game_date
model.tags['Round'] = rec["Round"]
model.tags['White'] = rec["White"]
model.tags['Black'] = rec["Black"]
model.tags['Result'] = result
if model.tags['Date']:
date_match = re.match(".*(\d{4}).(\d{2}).(\d{2}).*",
model.tags['Date'])
if date_match:
year, month, day = date_match.groups()
model.tags['Year'] = year
model.tags['Month'] = month
model.tags['Day'] = day
# non-mandatory tags
for tag in ('Annotator', 'ECO', 'WhiteElo', 'BlackElo', 'TimeControl'):
value = rec[tag]
if value:
model.tags[tag] = value
else:
model.tags[tag] = ""
if not self.pgn_is_string:
model.info = self.tag_database.get_info(rec)
if model.tags['TimeControl']:
secs, gain = parseTimeControlTag(model.tags['TimeControl'])
model.timed = True
model.timemodel.secs = secs
model.timemodel.gain = gain
model.timemodel.minutes = secs / 60
for tag, color in (('WhiteClock', WHITE), ('BlackClock', BLACK)):
if hasattr(rec, tag):
try:
millisec = parseClockTimeTag(rec[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)
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)
#.........这里部分代码省略.........