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


Python GameController.is_player1_to_move方法代码示例

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


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

示例1: test_is_player1_to_move

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import is_player1_to_move [as 别名]
    def test_is_player1_to_move(self):
        controller = GameController()
        controller._to_move = controller._player1
        self.assertTrue(controller.is_player1_to_move())

        controller._to_move = controller._player2
        self.assertFalse(controller.is_player1_to_move())
开发者ID:drtyrsa,项目名称:durak,代码行数:9,代码来源:tests.py

示例2: _play_game

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import is_player1_to_move [as 别名]
def _play_game(engine1_path, engine2_path, log_filename=''):
    engine1 = EngineWrapper(engine1_path)
    engine2 = EngineWrapper(engine2_path)
    controller = GameController(
        player1_name=engine1_path,
        player2_name=engine2_path,
        log_filename=log_filename,
    )
    new_game_data = controller.start_new_game()

    engine1.init(new_game_data['trump'])
    engine2.init(new_game_data['trump'])

    engine1.deal(
        new_game_data['player1_cards'],
        controller.get_game_data_for(controller.PLAYER1)
    )
    engine2.deal(
        new_game_data['player2_cards'],
        controller.get_game_data_for(controller.PLAYER2)
    )

    while True:
        if controller.state == controller.States.MOVING:
            if controller.is_player1_to_move():
                engine_to_move = engine1
            else:
                engine_to_move = engine2

            card = engine_to_move.move(
                controller.on_table,
                controller.get_game_data_for(controller.MOVER)
            )
            controller.register_move(card)

        elif controller.state == controller.States.RESPONDING:
            if controller.is_player1_to_move():
                engine_to_respond = engine2
            else:
                engine_to_respond = engine1

            card = engine_to_respond.respond(
                controller.on_table,
                controller.get_game_data_for(controller.RESPONDER)
            )
            controller.register_response(card)

        elif controller.state == controller.States.GIVING_MORE:
            if controller.is_player1_to_move():
                engine_to_give_more = engine1
            else:
                engine_to_give_more = engine2

            cards = engine_to_give_more.give_more(
                controller.on_table,
                controller.get_game_data_for(controller.MOVER)
            )
            controller.register_give_more(cards)

        elif controller.state == controller.States.DEALING:
            deal_data = controller.deal()
            engine1.deal(
                deal_data['player1_cards'],
                controller.get_game_data_for(controller.PLAYER1)
            )
            engine2.deal(
                deal_data['player2_cards'],
                controller.get_game_data_for(controller.PLAYER2)
            )

        if controller.is_game_over():
            break

    engine1.game_end()
    engine2.game_end()

    if controller.winner == controller.PLAYER1:
        return ENGINE1
    elif controller.winner == controller.PLAYER2:
        return ENGINE2
    else:
        return DRAW
开发者ID:drtyrsa,项目名称:durak,代码行数:84,代码来源:autoplay.py


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