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


Python GameModel.connect方法代码示例

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


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

示例1: coro

# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import connect [as 别名]
        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,代码行数:36,代码来源:savegame.py

示例2: do

# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import connect [as 别名]
def do(discoverer):
    game = GameModel(TimeModel(60,0))
    #game.connect('game_started', cb_gamestarted2)
    game.connect('game_ended', lambda *a: mainloop.quit())
    p0 = discoverer.initPlayerEngine(discoverer.getEngines()['rybka'], WHITE, 7, variants[NORMALCHESS], 60)
    p1 = discoverer.initPlayerEngine(discoverer.getEngines()['gnuchess'], BLACK, 7, variants[NORMALCHESS], 60)
    game.setPlayers([p0,p1])
    game.start()
开发者ID:fowode,项目名称:pychess,代码行数:10,代码来源:arena.py

示例3: runGame

# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import connect [as 别名]
def runGame():
    a, b = findMatch()
    if a == None:
        print("All games have now been played. Here are the final scores:")
        printResults()
        mainloop.quit()
        return
    current[0] = a
    current[1] = b
    
    game = GameModel(TimeModel(minutes*60,0))
    game.connect('game_started', cb_gamestarted)
    game.connect('game_ended', cb_gameended)
    p0 = discoverer.initPlayerEngine(engines[a], WHITE, 8, variants[NORMALCHESS], secs=minutes*60, incr=0, forcePonderOff=True)
    p1 = discoverer.initPlayerEngine(engines[b], BLACK, 8, variants[NORMALCHESS], secs=minutes*60, incr=0, forcePonderOff=True)
    game.setPlayers([p0,p1])
    game.start()
开发者ID:fowode,项目名称:pychess,代码行数:19,代码来源:arena.py

示例4: CECPTests

# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import connect [as 别名]
class CECPTests(unittest.TestCase):
    def setUp(self):
        self.engine = discoverer.getEngineByName("PyChess.py")

    def test(self):
        """ Play PyChess-PyChess 1 min variant games """

        if sys.platform == "win32":
            from asyncio.windows_events import ProactorEventLoop
            loop = ProactorEventLoop()
            asyncio.set_event_loop(loop)
        else:
            loop = asyncio.SelectorEventLoop()
            asyncio.set_event_loop(loop)

        loop = asyncio.get_event_loop()
        loop.set_debug(enabled=True)

        for vari in PYCHESS_VARIANTS:
            variant = variants[vari]

            def coro():
                self.p0 = yield from discoverer.initEngine(self.engine, WHITE, False)
                self.p1 = yield from discoverer.initEngine(self.engine, BLACK, False)

            loop.run_until_complete(coro())

            def optionsCallback(engine):
                engine.setOptionVariant(variant)
                engine.setOptionStrength(1, False)
                engine.setOptionTime(60, 0, 0)

            self.p0.connect("readyForOptions", optionsCallback)
            self.p1.connect("readyForOptions", optionsCallback)

            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)

            loop.run_until_complete(coro(variant))
开发者ID:teacoffee2017,项目名称:pychess,代码行数:66,代码来源:selfplay.py


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