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


Python GameController.get_game_data_for方法代码示例

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


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

示例1: test_game_data_for_public

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import get_game_data_for [as 别名]
 def test_game_data_for_public(self):
     controller = GameController()
     controller._trump = DurakCard('6H')
     controller._deck = [DurakCard('7S'), DurakCard('8D')]
     controller._on_table = [DurakCard('9C'), DurakCard('TH')]
     controller._discarded = [DurakCard('JD'), DurakCard('QS')]
     controller._player1.cards = CardSet(
         cards=(DurakCard('AC'), DurakCard('8S'), DurakCard('KS')),
         trump=controller._trump
     )
     controller._player2.cards = CardSet(
         cards=(DurakCard('KD'),), trump=controller._trump
     )
     controller._to_move = controller._player1
     self.assertDictEqual(
         controller.get_game_data_for(controller.PLAYER1),
         controller._get_game_data_for(controller._player1)
     )
     self.assertDictEqual(
         controller.get_game_data_for(controller.PLAYER2),
         controller._get_game_data_for(controller._player2)
     )
     self.assertDictEqual(
         controller.get_game_data_for(controller.MOVER),
         controller._get_game_data_for(controller._player1)
     )
     self.assertDictEqual(
         controller.get_game_data_for(controller.RESPONDER),
         controller._get_game_data_for(controller._player2)
     )
开发者ID:drtyrsa,项目名称:durak,代码行数:32,代码来源:tests.py

示例2: PlayFrame

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import get_game_data_for [as 别名]

#.........这里部分代码省略.........
        )
        self.Bind(wx.EVT_MENU, None, self._by_winner_menu_item)
        item = menu.Append(
            wx.ID_ANY, u'Выбрать движок...', u'Выбрать компьютерного соперника'
        )
        self.Bind(wx.EVT_MENU, self._on_select_engine, item)
        self.menu.Append(menu, u'Настройки')

        self.SetMenuBar(self.menu)

    def _on_close(self, event):
        self._stop_engine()
        if event.GetEventType() in wx.EVT_CLOSE.evtType:
            event.Skip()
        else:
            self.Close()

    def _start_new_game(self, event=None):
        self._stop_engine()
        self._engine = EngineWrapper(self._get_engine_path())
        self.SetTitle('Durak GUI (vs %s)' % self._get_engine_path())

        new_game_data = self._controller.start_new_game(
            ignore_winner=not self._by_winner_menu_item.IsChecked()
        )
        self._trump = new_game_data['trump']

        self._deck.set_card_count(self._controller.deck_count)
        self._deck.set_opened_trump(self._trump)

        self._engine.init(self._trump)
        self._engine.deal(
            new_game_data['player2_cards'],
            self._controller.get_game_data_for(self.ENGINE)
        )
        self._top_player_sizer.set_count(len(new_game_data['player2_cards']))

        self._table.remove_all()

        self._bottom_player_sizer.remove_all()
        self._bottom_player_sizer.trump = self._trump
        for card in new_game_data['player1_cards']:
            self._bottom_player_sizer.add_card(card)
        self._bottom_player_sizer.Layout()

        self._set_enabled_cards_and_controls()

        self._panel.Layout()
        self.Layout()
        self.Refresh()

        if self._controller.to_move == self.ENGINE:
            self._engine_move()

    def _set_enabled_cards_and_controls(self):
        human_cards = self._bottom_player_sizer.cards
        on_table = self._table.cards
        self._control_sizer.hide_all()

        if (self._controller.to_move == self.HUMAN and
                self._controller.state == self._controller.States.MOVING):
            self._bottom_player_sizer.set_enabled_cards(
                human_cards.cards_that_can_be_added_to(on_table)
            )
            if on_table:
                self._control_sizer.show_button(self._control_sizer.DISCARD)
开发者ID:drtyrsa,项目名称:durak,代码行数:70,代码来源:play.py

示例3: _play_game

# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import get_game_data_for [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.get_game_data_for方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。