当前位置: 首页>>代码示例>>Python>>正文


Python GameModel.tags[et['tag_name']]方法代码示例

本文整理汇总了Python中pychess.Utils.GameModel.GameModel.tags[et['tag_name']]方法的典型用法代码示例。如果您正苦于以下问题:Python GameModel.tags[et['tag_name']]方法的具体用法?Python GameModel.tags[et['tag_name']]怎么用?Python GameModel.tags[et['tag_name']]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pychess.Utils.GameModel.GameModel的用法示例。


在下文中一共展示了GameModel.tags[et['tag_name']]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: loadToModel

# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import tags[et['tag_name']] [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)

#.........这里部分代码省略.........
开发者ID:teacoffee2017,项目名称:pychess,代码行数:103,代码来源:pgn.py


注:本文中的pychess.Utils.GameModel.GameModel.tags[et['tag_name']]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。