本文整理汇总了Python中durak.controller.GameController.deal方法的典型用法代码示例。如果您正苦于以下问题:Python GameController.deal方法的具体用法?Python GameController.deal怎么用?Python GameController.deal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类durak.controller.GameController
的用法示例。
在下文中一共展示了GameController.deal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deal_with_no_response
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [as 别名]
def test_deal_with_no_response(self):
controller = GameController()
controller._trump = DurakCard('6H')
controller._state = controller.States.DEALING
controller._no_response = True
controller._discarded = []
controller._to_move = controller._player1
controller._player1.cards = {DurakCard('JH')}
controller._player2.cards = set()
controller._deck = []
controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
controller._on_table.given_more = {DurakCard('7S'), DurakCard('7H')}
controller._logger_enabled = False
controller.deal()
self.assertItemsEqual(
controller._player2.cards,
{
DurakCard('6S'),
DurakCard('6H'),
DurakCard('7S'),
DurakCard('7H')
}
)
self.assertFalse(controller._no_response)
self.assertEqual(controller._to_move, controller._player1)
self.assertEqual(controller._state, controller.States.MOVING)
示例2: test_deal_clears_the_table
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [as 别名]
def test_deal_clears_the_table(self):
controller = GameController()
controller._trump = DurakCard('6H')
controller._state = controller.States.DEALING
controller._no_response = True
controller._discarded = []
controller._to_move = controller._player1
controller._player1.cards = set()
controller._player2.cards = set()
controller._deck = []
controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
controller._on_table.given_more = {DurakCard('7S'), DurakCard('7H')}
controller._logger_enabled = False
controller.deal()
self.assertSequenceEqual(controller._on_table, [])
self.assertItemsEqual(controller._on_table.given_more, set())
示例3: test_deal_no_cards_needed
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [as 别名]
def test_deal_no_cards_needed(self):
controller = GameController()
controller._trump = DurakCard('6H')
controller._state = controller.States.DEALING
controller._no_response = False
controller._discarded = []
controller._to_move = controller._player1
controller._player1.cards = {
DurakCard('6S'),
DurakCard('6H'),
DurakCard('8S'),
DurakCard('8H'),
DurakCard('9S'),
DurakCard('9H')
}
controller._player2.cards = {DurakCard('7S'), DurakCard('7H')}
controller._deck = [
DurakCard('AS'),
DurakCard('AH'),
DurakCard('KS'),
DurakCard('KH'),
DurakCard('QS'),
DurakCard('QH'),
DurakCard('JS'),
DurakCard('JH'),
DurakCard('TS'),
DurakCard('TH'),
]
controller._on_table = Table()
controller._logger_enabled = False
controller.deal()
self.assertItemsEqual(
controller._player1.cards, {
DurakCard('6S'),
DurakCard('6H'),
DurakCard('8S'),
DurakCard('8H'),
DurakCard('9S'),
DurakCard('9H')
}
)
示例4: test_deal_with_response
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [as 别名]
def test_deal_with_response(self):
controller = GameController()
controller._trump = DurakCard('6H')
controller._state = controller.States.DEALING
controller._no_response = False
controller._discarded = []
controller._to_move = controller._player1
controller._player1.cards = {DurakCard('JH')}
controller._player2.cards = {DurakCard('JS')}
controller._deck = []
controller._on_table = Table([DurakCard('6S'), DurakCard('6H')])
controller._logger_enabled = False
controller.deal()
self.assertSequenceEqual(
controller._discarded, [DurakCard('6S'), DurakCard('6H')]
)
self.assertEqual(controller._to_move, controller._player2)
self.assertEqual(controller._state, controller.States.MOVING)
示例5: test_deal_cards_and_return_value
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [as 别名]
def test_deal_cards_and_return_value(self):
controller = GameController()
controller._trump = DurakCard('6H')
controller._state = controller.States.DEALING
controller._no_response = False
controller._discarded = []
controller._to_move = controller._player1
controller._player1.cards = {DurakCard('6S'), DurakCard('6H')}
controller._player2.cards = {DurakCard('7S'), DurakCard('7H')}
controller._deck = [
DurakCard('AS'),
DurakCard('AH'),
DurakCard('KS'),
DurakCard('KH'),
DurakCard('QS'),
DurakCard('QH'),
DurakCard('JS'),
DurakCard('JH'),
DurakCard('TS'),
DurakCard('TH'),
]
controller._on_table = Table()
controller._logger_enabled = False
return_value = controller.deal()
self.assertItemsEqual(
controller._player1.cards, [
DurakCard('6S'),
DurakCard('6H'),
DurakCard('AS'),
DurakCard('AH'),
DurakCard('KS'),
DurakCard('KH'),
]
)
self.assertItemsEqual(
controller._player2.cards, [
DurakCard('7S'),
DurakCard('7H'),
DurakCard('QS'),
DurakCard('QH'),
DurakCard('JS'),
DurakCard('JH'),
]
)
self.assertSequenceEqual(
controller._deck, [DurakCard('TS'), DurakCard('TH')]
)
self.assertDictEqual(return_value, {
'player1_cards': controller._player1.cards - {DurakCard('6S'), DurakCard('6H')},
'player2_cards': controller._player2.cards - {DurakCard('7S'), DurakCard('7H')},
})
示例6: PlayFrame
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [as 别名]
#.........这里部分代码省略.........
u'Ход под дурака',
u'В новой игре ходит первым победитель в предыдущей'
)
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)
)
示例7: _play_game
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [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
示例8: test_deal_is_error_if_state_is_not_dealing
# 需要导入模块: from durak.controller import GameController [as 别名]
# 或者: from durak.controller.GameController import deal [as 别名]
def test_deal_is_error_if_state_is_not_dealing(self):
controller = GameController()
controller._trump = DurakCard('6H')
controller._state = controller.States.MOVING
with self.assertRaises(exes.InvalidAction):
controller.deal()