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


Python GameModel.GameModel类代码示例

本文整理汇总了Python中pychess.Utils.GameModel.GameModel的典型用法代码示例。如果您正苦于以下问题:Python GameModel类的具体用法?Python GameModel怎么用?Python GameModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: __init__

    def __init__ (self, connection, ficsgame, timemodel):
        assert ficsgame.game_type in GAME_TYPES.values()
        GameModel.__init__(self, timemodel, ficsgame.game_type.variant)
        self.connection = connection
        self.ficsgame = ficsgame
        self.ficsplayers = (ficsgame.wplayer, ficsgame.bplayer)
        self.gmwidg_ready = threading.Event()

        connections = self.connections
        connections[connection.bm].append(connection.bm.connect("boardUpdate", self.onBoardUpdate))
        connections[connection.bm].append(connection.bm.connect("obsGameEnded", self.onGameEnded))
        connections[connection.bm].append(connection.bm.connect("curGameEnded", self.onGameEnded))
        connections[connection.bm].append(connection.bm.connect("gamePaused", self.onGamePaused))
        connections[connection.bm].append(connection.bm.connect("madeExamined", self.onMadeExamined))
        connections[connection.bm].append(connection.bm.connect("madeUnExamined", self.onMadeUnExamined))
        connections[connection.om].append(connection.om.connect("onActionError", self.onActionError))
        connections[connection.cm].append(connection.cm.connect("kibitzMessage", self.onKibitzMessage))
        connections[connection.cm].append(connection.cm.connect("whisperMessage", self.onWhisperMessage))
        connections[connection.cm].append(connection.cm.connect("observers_received", self.onObserversReceived))
        connections[connection].append(connection.connect("disconnected", self.onDisconnected))

        rated = "rated" if ficsgame.rated else "unrated"
        # This is in the format that ficsgames.org writes these PGN headers
        self.tags["Event"] = "FICS %s %s game" % (rated, ficsgame.game_type.fics_name)
        self.tags["Site"] = "freechess.org"
开发者ID:ggjj1122,项目名称:pychess,代码行数:25,代码来源:ICGameModel.py

示例2: coro

        def coro():
            gamemodel = GameModel(TimeModel(1, 0))

            player0tup = (LOCAL, Human, (WHITE, "w"), "w")
            player1tup = (LOCAL, Human, (BLACK, "b"), "b")

            def on_game_end(game, state, event):
                event.set()

            event = asyncio.Event()
            gamemodel.connect("game_ended", on_game_end, event)

            def on_players_changed(game):
                # fill fools mate moves to players move queue
                p0 = game.players[0]
                p0.move_queue.put_nowait(Move(newMove(F2, F3)))
                p0.move_queue.put_nowait(Move(newMove(G2, G4)))

                p1 = gamemodel.players[1]
                p1.move_queue.put_nowait(Move(newMove(E7, E5)))
                p1.move_queue.put_nowait(Move(newMove(D8, H4)))

            gamemodel.connect("players_changed", on_players_changed)

            asyncio.async(self.games_persp.generalStart(gamemodel, player0tup, player1tup))

            # waiting for game end ...
            yield from event.wait()

            fen = "rnb1kbnr/pppp1ppp/8/4p3/6Pq/5P2/PPPPP2P/RNBQKBNR w KQkq - 1 3"
            self.assertEqual(gamemodel.boards[-1].board.asFen(), fen)

            # Now save our game to pychess.pgn
            self.games_persp.saveGamePGN(gamemodel)
开发者ID:teacoffee2017,项目名称:pychess,代码行数:34,代码来源:savegame.py

示例3: acceptReceived

 def acceptReceived(self, player, offer):
     log.debug("ICGameModel.acceptReceived: accepter=%s %s" %
               (repr(player), offer))
     if player.__type__ == LOCAL:
         GameModel.acceptReceived(self, player, offer)
         log.debug("ICGameModel.acceptReceived: connection.om.accept(%s)" % offer)
         self.connection.om.accept(offer)
开发者ID:leogregianin,项目名称:pychess,代码行数:7,代码来源:ICGameModel.py

示例4: terminate

    def terminate(self):
        for obj in self.connections:
            for handler_id in self.connections[obj]:
                if obj.handler_is_connected(handler_id):
                    obj.disconnect(handler_id)

        self.connections = None
        GameModel.terminate(self)
开发者ID:ME7ROPOLIS,项目名称:pychess,代码行数:8,代码来源:ICGameModel.py

示例5: loadToModel

    def loadToModel(self, rec, position, model=None):
        if not model:
            model = GameModel()

        if "Variant" in rec:
            model.variant = FischerandomBoard

        fieldlist = rec["FEN"].split(" ")
        if len(fieldlist) == 4:
            fen = rec["FEN"]
            opcodestr = ""

        elif len(fieldlist) > 4:
            fen = " ".join(fieldlist[:4])
            opcodestr = " ".join(fieldlist[4:])

        else:
            raise LoadingError("EPD string can not have less than 4 field")

        opcodes = {}
        for opcode in map(str.strip, opcodestr.split(";")):
            space = opcode.find(" ")
            if space == -1:
                opcodes[opcode] = True
            else:
                opcodes[opcode[:space]] = opcode[space + 1:]

        if "hmvc" in opcodes:
            fen += " " + opcodes["hmvc"]
        else:
            fen += " 0"

        if "fmvn" in opcodes:
            fen += " " + opcodes["fmvn"]
        else:
            fen += " 1"

        model.boards = [model.variant(setup=fen)]
        model.variations = [model.boards]
        model.status = WAITING_TO_START

        # rc is kinda broken
        # if "rc" in opcodes:
        #    model.boards[0].board.rc = int(opcodes["rc"])

        if "resign" in opcodes:
            if fieldlist[1] == "w":
                model.status = BLACKWON
            else:
                model.status = WHITEWON
            model.reason = WON_RESIGN

        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
开发者ID:bboutkov,项目名称:pychess,代码行数:58,代码来源:epd.py

示例6: terminate

    def terminate(self):
        for obj in self.connections:
            for handler_id in self.connections[obj]:
                if obj.handler_is_connected(handler_id):
                    obj.disconnect(handler_id)

        self.connections = None
        GameModel.terminate(self)
        if self.kibitz_task is not None:
            self.kibitz_task.cancel()
开发者ID:leogregianin,项目名称:pychess,代码行数:10,代码来源:ICGameModel.py

示例7: loadToModel

    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
开发者ID:leogregianin,项目名称:pychess,代码行数:28,代码来源:fen.py

示例8: end

 def end (self, status, reason):
     if self.status in UNFINISHED_STATES:
         self.__disconnect()
         
         if self.isObservationGame():
             self.connection.bm.unobserve(self.ficsgame)
         else:
             self.connection.om.offer(Offer(ABORT_OFFER), -1)
             self.connection.om.offer(Offer(RESIGNATION), -1)
     
     GameModel.end(self, status, reason)
开发者ID:btrent,项目名称:knave,代码行数:11,代码来源:ICGameModel.py

示例9: end

 def end (self, status, reason):
     if self.status in UNFINISHED_STATES:
         self.__disconnect()
         
         if self.inControl:
             self.connection.om.offer(Offer(ABORT_OFFER), -1)
             self.connection.om.offer(Offer(RESIGNATION), -1)
         else:
             self.connection.bm.unobserve(self.gameno)
     
     GameModel.end(self, status, reason)
开发者ID:jskurka,项目名称:PyChess-Learning-Module,代码行数:11,代码来源:ICGameModel.py

示例10: feed_book

    def feed_book(self, records, positions):
        for rec in records:
            model = GameModel()

            if rec["Result"] == DRAW:
                score = (1, 1)
            elif rec["Result"] == WHITEWON:
                score = (2, 0)
            elif rec["Result"] == BLACKWON:
                score = (0, 2)
            else:
                score = (0, 0)

            fenstr = rec["FEN"]
            variant = self.chessfile.get_variant(rec)

            if variant:
                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:
                    continue
            else:
                board.applyFen(FEN_START)

            boards = [board]

            movetext = self.chessfile.get_movetext(rec)
            boards = self.chessfile.parse_movetext(movetext, boards[0], -1)

            for board in boards:
                if board.plyCount > BOOK_DEPTH:
                    break
                move = board.lastMove
                if move is not None:
                    poly_move = toPolyglot(board.prev, move)
                    # move_str = "%s%s" % (reprCord[FCORD(move)], reprCord[TCORD(move)])
                    # print("%0.16x" % board.prev.hash, poly_move, board.prev.asFen(), move_str)
                    if board.prev.hash in positions:
                        if poly_move in positions[board.prev.hash]:
                            positions[board.prev.hash][poly_move] += score[board.prev.color]
                        else:
                            positions[board.prev.hash][poly_move] = score[board.prev.color]
                    else:
                        # board.prev.asFen(), move_str,
                        positions[board.prev.hash] = {poly_move: score[board.prev.color]}
开发者ID:leogregianin,项目名称:pychess,代码行数:52,代码来源:__init__.py

示例11: __init__

 def __init__ (self, connection, gameno, timemodel, variant, rated=False):
     GameModel.__init__(self, timemodel, variant)
     self.connection = connection
     self.gameno = gameno
     
     connections = self.connections
     connections[connection.bm].append(connection.bm.connect("boardUpdate", self.onBoardUpdate))
     connections[connection.bm].append(connection.bm.connect("obsGameEnded", self.onGameEnded))
     connections[connection.bm].append(connection.bm.connect("curGameEnded", self.onGameEnded))
     connections[connection.bm].append(connection.bm.connect("gamePaused", self.onGamePaused))
     connections[connection.om].append(connection.om.connect("onActionError", self.onActionError))
     connections[connection].append(connection.connect("disconnected", self.onDisconnected))
     
     self.inControl = True
     self.rated = rated
开发者ID:jskurka,项目名称:PyChess-Learning-Module,代码行数:15,代码来源:ICGameModel.py

示例12: coro

            def coro(variant):
                self.game = GameModel(TimeModel(60, 0), variant)
                self.game.setPlayers([self.p0, self.p1])

                def on_game_end(game, state, event):
                    event.set()

                event = asyncio.Event()
                self.game.connect("game_ended", on_game_end, event)

                self.p0.prestart()
                self.p1.prestart()

                if self.game.variant.need_initial_board:
                    for player in self.game.players:
                        player.setOptionInitialBoard(self.game)

                print(variant.name)
                self.game.start()

                yield from event.wait()

                pgn = StringIO()
                print(save(pgn, self.game))

                self.assertIsNone(self.p0.invalid_move)
                self.assertIsNone(self.p1.invalid_move)
开发者ID:teacoffee2017,项目名称:pychess,代码行数:27,代码来源:selfplay.py

示例13: loadToModel

 def loadToModel (self, gameno, position, model=None):
     if not model: model = GameModel()
     
     # We have to set full move number to 1 to make sure LBoard and GameModel
     # are synchronized.
     #fenlist = self.games[gameno].split(" ")
     #if len(fenlist) == 6:
     #    fen = " ".join(fenlist[:5]) + " 1" 
     fen = self.games[gameno]
     
     model.boards = [model.variant.board(setup=fen)]
     model.variations = [model.boards]
     if model.status == WAITING_TO_START:
         model.status, model.reason = getStatus(model.boards[-1])
     
     return model
开发者ID:btrent,项目名称:knave,代码行数:16,代码来源:fen.py

示例14: row_activated

    def row_activated(self, widget, path, col):
        print(self.modelsort.convert_path_to_child_path(path)[0])
        game_id = self.liststore[self.modelsort.convert_path_to_child_path(
            path)[0]][0]
        print("game_id=%s" % game_id)
        gameno = self.id_list.index(game_id)
        print("gameno=%s" % gameno)

        gamemodel = GameModel()
        wp, bp = self.chessfile.get_player_names(gameno)
        p0 = (LOCAL, Human, (WHITE, wp), wp)
        p1 = (LOCAL, Human, (BLACK, bp), bp)
        self.chessfile.loadToModel(gameno, -1, gamemodel)

        gamemodel.status = WAITING_TO_START
        game_handler.generalStart(gamemodel, p0, p1)
开发者ID:ME7ROPOLIS,项目名称:pychess,代码行数:16,代码来源:gamelist.py

示例15: end

    def end(self, status, reason):
        if self.examined:
            self.connection.bm.unexamine()

        if self.status in UNFINISHED_STATES:
            self.__disconnect()

            if self.isObservationGame():
                self.connection.bm.unobserve(self.ficsgame)
            else:
                self.connection.om.offer(Offer(ABORT_OFFER))
                self.connection.om.offer(Offer(RESIGNATION))

        if status == KILLED:
            GameModel.kill(self, reason)
        else:
            GameModel.end(self, status, reason)
开发者ID:leogregianin,项目名称:pychess,代码行数:17,代码来源:ICGameModel.py


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