Пример #1
0
 def test_game_data_for_private(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)
     self.assertDictEqual(
         controller._get_game_data_for(controller._player1), {
             'trump': str(controller._trump),
             'deck_count': len(controller._deck),
             'enemy_count': len(controller._player2.cards),
             'on_table': map(str, controller._on_table),
             'discarded': map(str, controller._discarded),
         })
     self.assertDictEqual(
         controller._get_game_data_for(controller._player2), {
             'trump': str(controller._trump),
             'deck_count': len(controller._deck),
             'enemy_count': len(controller._player1.cards),
             'on_table': map(str, controller._on_table),
             'discarded': map(str, controller._discarded),
         })
Пример #2
0
 def test_game_data_for_private(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
     )
     self.assertDictEqual(
         controller._get_game_data_for(controller._player1), {
             'trump': str(controller._trump),
             'deck_count': len(controller._deck),
             'enemy_count': len(controller._player2.cards),
             'on_table': map(str, controller._on_table),
             'discarded': map(str, controller._discarded),
         }
     )
     self.assertDictEqual(
         controller._get_game_data_for(controller._player2), {
             'trump': str(controller._trump),
             'deck_count': len(controller._deck),
             'enemy_count': len(controller._player1.cards),
             'on_table': map(str, controller._on_table),
             'discarded': map(str, controller._discarded),
         }
     )
Пример #3
0
    def test_register_give_more_is_error_if_player_can_not_give_these_cards(
            self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH'),
                                                   DurakCard('6H')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(
            DurakCard('7C'),
            DurakCard('7H'),
            DurakCard('7D'),
            DurakCard('7S'),
        ),
                                            trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.InvalidCard):
            controller.register_give_more(
                [DurakCard('AC'),
                 DurakCard('AH'),
                 DurakCard('6H')])
Пример #4
0
 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))
Пример #5
0
    def test_successful_register_give_more(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._deck = [DurakCard('JH')]
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('6S'), DurakCard('6H')),
            trump=controller._trump
        )
        controller._player2.cards = CardSet(
            cards=(DurakCard('7C'), DurakCard('7H'), DurakCard('7D')),
            trump=controller._trump
        )
        controller._on_table = Table([DurakCard('6D')])

        controller.register_give_more([DurakCard('6S'), DurakCard('6H')])

        self.assertItemsEqual(controller._player1.cards, [DurakCard('AC')])
        self.assertSequenceEqual(controller._on_table, [DurakCard('6D')])
        self.assertItemsEqual(
            controller._on_table.given_more, [DurakCard('6S'), DurakCard('6H')]
        )
        self.assertEqual(controller._state, controller.States.DEALING)
Пример #6
0
    def test_register_give_more_is_error_if_player_can_not_give_these_cards(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH'), DurakCard('6H')),
            trump=controller._trump
        )
        controller._player2.cards = CardSet(
            cards=(
                DurakCard('7C'),
                DurakCard('7H'),
                DurakCard('7D'),
                DurakCard('7S'),
            ),
            trump=controller._trump
        )
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.InvalidCard):
            controller.register_give_more([
                DurakCard('AC'), DurakCard('AH'), DurakCard('6H')
            ])
Пример #7
0
    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)
Пример #8
0
 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)
     )
Пример #9
0
    def test_successful_register_give_more(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._deck = [DurakCard('JH')]
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('6S'),
                                                   DurakCard('6H')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(DurakCard('7C'),
                                                   DurakCard('7H'),
                                                   DurakCard('7D')),
                                            trump=controller._trump)
        controller._on_table = Table([DurakCard('6D')])

        controller.register_give_more([DurakCard('6S'), DurakCard('6H')])

        self.assertItemsEqual(controller._player1.cards, [DurakCard('AC')])
        self.assertSequenceEqual(controller._on_table, [DurakCard('6D')])
        self.assertItemsEqual(
            controller._on_table.given_more,
            [DurakCard('6S'), DurakCard('6H')])
        self.assertEqual(controller._state, controller.States.DEALING)
Пример #10
0
    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)
Пример #11
0
    def test_register_response_goes_to_dealing_if_card_is_none_and_mover_has_no_cards(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(), trump=controller._trump)

        controller.register_response(None)

        self.assertEqual(controller._state, controller.States.DEALING)
        self.assertTrue(controller._no_response)
Пример #12
0
    def test_register_response_is_error_if_player_can_not_add_this_card(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player2
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH')), trump=controller._trump
        )
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.InvalidCard):
            controller.register_response(DurakCard('AC'))
Пример #13
0
    def test_register_move_is_error_if_player_does_have_this_card(self):
        controller = GameController()
        controller._state = controller.States.MOVING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH')), trump=controller._trump
        )
        controller._on_table = []

        with self.assertRaises(exes.PlayerDoesNotHaveCard):
            controller.register_move(DurakCard('6D'))
Пример #14
0
    def test_register_response_goes_to_dealing_if_card_is_none_and_mover_has_no_cards(
            self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(), trump=controller._trump)

        controller.register_response(None)

        self.assertEqual(controller._state, controller.States.DEALING)
        self.assertTrue(controller._no_response)
Пример #15
0
    def test_register_response_is_error_if_player_can_not_add_this_card(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player2
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH')),
                                            trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.InvalidCard):
            controller.register_response(DurakCard('AC'))
Пример #16
0
    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')},
        })
Пример #17
0
    def test_check_for_game_over_is_draw_if_both_players_have_no_cards(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._deck = []
        controller._player1.cards = CardSet(cards=(), trump=controller._trump)
        controller._player2.cards = CardSet(cards=(), trump=controller._trump)
        controller._state = controller.States.MOVING
        controller._logger_enabled = False

        controller._check_for_game_over()
        self.assertTrue(controller._state is None)
        self.assertTrue(controller._winner is None)
Пример #18
0
    def test_check_for_game_over_is_draw_if_both_players_have_no_cards(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._deck = []
        controller._player1.cards = CardSet(cards=(), trump=controller._trump)
        controller._player2.cards = CardSet(cards=(), trump=controller._trump)
        controller._state = controller.States.MOVING
        controller._logger_enabled = False

        controller._check_for_game_over()
        self.assertTrue(controller._state is None)
        self.assertTrue(controller._winner is None)
Пример #19
0
    def test_register_move_is_error_if_player_does_have_this_card(self):
        controller = GameController()
        controller._state = controller.States.MOVING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH')),
                                            trump=controller._trump)
        controller._on_table = []

        with self.assertRaises(exes.PlayerDoesNotHaveCard):
            controller.register_move(DurakCard('6D'))
Пример #20
0
    def test_register_response_goes_to_giving_more_if_card_is_none(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'), ),
                                            trump=controller._trump)

        controller.register_response(None)

        self.assertEqual(controller._state, controller.States.GIVING_MORE)
        self.assertTrue(controller._no_response)
Пример #21
0
    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')},
            })
Пример #22
0
    def test_register_response_goes_to_giving_more_if_card_is_none(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'),), trump=controller._trump
        )

        controller.register_response(None)

        self.assertEqual(controller._state, controller.States.GIVING_MORE)
        self.assertTrue(controller._no_response)
Пример #23
0
 def test_check_for_game_over_does_nothing_if_both_players_have_cards(self):
     controller = GameController()
     controller._trump = DurakCard('6H')
     controller._deck = []
     controller._player1.cards = CardSet(
         cards=(DurakCard('AC'), DurakCard('8S')), trump=controller._trump
     )
     controller._player2.cards = CardSet(
         cards=(DurakCard('KD'), DurakCard('KS')), trump=controller._trump
     )
     controller._state = controller.States.MOVING
     controller._check_for_game_over()
     self.assertEqual(controller._state, controller.States.MOVING)
Пример #24
0
 def test_check_for_game_over_does_nothing_if_both_players_have_cards(self):
     controller = GameController()
     controller._trump = DurakCard('6H')
     controller._deck = []
     controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                DurakCard('8S')),
                                         trump=controller._trump)
     controller._player2.cards = CardSet(cards=(DurakCard('KD'),
                                                DurakCard('KS')),
                                         trump=controller._trump)
     controller._state = controller.States.MOVING
     controller._check_for_game_over()
     self.assertEqual(controller._state, controller.States.MOVING)
Пример #25
0
 def test_check_for_game_over_does_nothing_if_responder_can_beat_with_last_card(
         self):
     controller = GameController()
     controller._state = controller.States.RESPONDING
     controller._deck = []
     controller._trump = DurakCard('6H')
     controller._player1.cards = CardSet(cards=(), trump=controller._trump)
     controller._player2.cards = CardSet(cards=(DurakCard('KD'), ),
                                         trump=controller._trump)
     controller._to_move = controller._player1
     controller._on_table = [DurakCard('QD')]
     controller._check_for_game_over()
     self.assertEqual(controller._state, controller.States.RESPONDING)
Пример #26
0
 def test_check_for_game_over_does_nothing_if_responder_can_beat_with_last_card(self):
     controller = GameController()
     controller._state = controller.States.RESPONDING
     controller._deck = []
     controller._trump = DurakCard('6H')
     controller._player1.cards = CardSet(cards=(), trump=controller._trump)
     controller._player2.cards = CardSet(
         cards=(DurakCard('KD'),), trump=controller._trump
     )
     controller._to_move = controller._player1
     controller._on_table = [DurakCard('QD')]
     controller._check_for_game_over()
     self.assertEqual(controller._state, controller.States.RESPONDING)
Пример #27
0
 def test_get_first_to_move_by_trump_if_only_no_trumps_exist(self):
     controller = GameController()
     controller._trump = DurakCard('6H')
     controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                DurakCard('8S')),
                                         trump=controller._trump)
     controller._player2.cards = CardSet(cards=(DurakCard('KS'),
                                                DurakCard('KD')),
                                         trump=controller._trump)
     with patch('durak.controller.random') as random_mock:
         result = controller._get_first_to_move_by_trump()
         self.assertEqual(result, random_mock.choice.return_value)
         random_mock.choice.assert_called_once_with(
             [controller._player1, controller._player2])
Пример #28
0
    def test_register_response_not_allows_moving_if_moving_has_no_cards(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player2
        controller._trump = DurakCard('6H')
        controller._deck = [DurakCard('JH')]
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH')), trump=controller._trump
        )
        controller._player2.cards = CardSet(cards=(), trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        controller.register_response(DurakCard('AH'))

        self.assertEqual(controller.state, controller.States.DEALING)
Пример #29
0
    def test_register_response_not_allows_moving_if_moving_has_no_cards(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player2
        controller._trump = DurakCard('6H')
        controller._deck = [DurakCard('JH')]
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(), trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        controller.register_response(DurakCard('AH'))

        self.assertEqual(controller.state, controller.States.DEALING)
Пример #30
0
    def test_register_give_more_is_error_if_max_count_is_exceeded(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(DurakCard('7C'), ),
                                            trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.TooMuchGiveMoreCards):
            controller.register_give_more([DurakCard('6S'), DurakCard('6H')])
Пример #31
0
 def test_get_first_to_move_by_trump_if_only_no_trumps_exist(self):
     controller = GameController()
     controller._trump = DurakCard('6H')
     controller._player1.cards = CardSet(
         cards=(DurakCard('AC'), DurakCard('8S')), trump=controller._trump
     )
     controller._player2.cards = CardSet(
         cards=(DurakCard('KS'), DurakCard('KD')), trump=controller._trump
     )
     with patch('durak.controller.random') as random_mock:
         result = controller._get_first_to_move_by_trump()
         self.assertEqual(result, random_mock.choice.return_value)
         random_mock.choice.assert_called_once_with(
             [controller._player1, controller._player2]
         )
Пример #32
0
    def test_register_give_more_is_error_if_max_count_is_exceeded(self):
        controller = GameController()
        controller._state = controller.States.GIVING_MORE
        controller._no_response = True
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH')), trump=controller._trump
        )
        controller._player2.cards = CardSet(
            cards=(DurakCard('7C'),), trump=controller._trump
        )
        controller._on_table = [DurakCard('6D')]

        with self.assertRaises(exes.TooMuchGiveMoreCards):
            controller.register_give_more([DurakCard('6S'), DurakCard('6H')])
Пример #33
0
    def test_register_response_moves_card_from_player_to_table(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player2
        controller._trump = DurakCard('6H')
        controller._deck = [DurakCard('JH')]
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('AH')),
                                            trump=controller._trump)
        controller._on_table = [DurakCard('6D')]

        controller.register_response(DurakCard('AH'))

        self.assertItemsEqual(controller._player1.cards, [DurakCard('AC')])
        self.assertEqual(controller._on_table,
                         [DurakCard('6D'), DurakCard('AH')])
Пример #34
0
    def test_get_first_to_move_by_trump_if_both_trumps_exist(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(cards=(DurakCard('7H'),
                                                   DurakCard('8S')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(DurakCard('9H'),
                                                   DurakCard('KD')),
                                            trump=controller._trump)
        self.assertEqual(controller._get_first_to_move_by_trump(),
                         controller._player1)

        controller._player1.cards = CardSet(cards=(DurakCard('AH'),
                                                   DurakCard('8S')),
                                            trump=controller._trump)
        self.assertEqual(controller._get_first_to_move_by_trump(),
                         controller._player2)
Пример #35
0
    def test_register_response_moves_card_from_player_to_table(self):
        controller = GameController()
        controller._state = controller.States.RESPONDING
        controller._to_move = controller._player2
        controller._trump = DurakCard('6H')
        controller._deck = [DurakCard('JH')]
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('AH')), trump=controller._trump
        )
        controller._on_table = [DurakCard('6D')]

        controller.register_response(DurakCard('AH'))

        self.assertItemsEqual(controller._player1.cards, [DurakCard('AC')])
        self.assertEqual(
            controller._on_table, [DurakCard('6D'), DurakCard('AH')]
        )
Пример #36
0
    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())
Пример #37
0
    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())
Пример #38
0
    def test_successful_register_move(self):
        controller = GameController()
        controller._state = controller.States.MOVING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._deck = [DurakCard('6H')]
        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('7H')), trump=controller._trump
        )
        controller._on_table = [DurakCard('AD'), DurakCard('AS')]

        controller.register_move(DurakCard('AC'))

        self.assertItemsEqual(controller._player1.cards, (DurakCard('7H'),))
        self.assertEqual(
            controller._on_table,
            [DurakCard('AD'), DurakCard('AS'), DurakCard('AC')]
        )
        self.assertEqual(controller._state, controller.States.RESPONDING)
Пример #39
0
    def test_get_first_to_move_by_trump_if_both_trumps_exist(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._player1.cards = CardSet(
            cards=(DurakCard('7H'), DurakCard('8S')), trump=controller._trump
        )
        controller._player2.cards = CardSet(
            cards=(DurakCard('9H'), DurakCard('KD')), trump=controller._trump
        )
        self.assertEqual(
            controller._get_first_to_move_by_trump(), controller._player1
        )

        controller._player1.cards = CardSet(
            cards=(DurakCard('AH'), DurakCard('8S')), trump=controller._trump
        )
        self.assertEqual(
            controller._get_first_to_move_by_trump(), controller._player2
        )
Пример #40
0
    def test_successful_register_move(self):
        controller = GameController()
        controller._state = controller.States.MOVING
        controller._to_move = controller._player1
        controller._trump = DurakCard('6H')
        controller._deck = [DurakCard('6H')]
        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('7H')),
                                            trump=controller._trump)
        controller._on_table = [DurakCard('AD'), DurakCard('AS')]

        controller.register_move(DurakCard('AC'))

        self.assertItemsEqual(controller._player1.cards, (DurakCard('7H'), ))
        self.assertEqual(controller._on_table,
                         [DurakCard('AD'),
                          DurakCard('AS'),
                          DurakCard('AC')])
        self.assertEqual(controller._state, controller.States.RESPONDING)
Пример #41
0
    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')
            }
        )
Пример #42
0
    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')
            })
Пример #43
0
    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)
Пример #44
0
    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)
Пример #45
0
    def test_check_for_game_over_player_wins_if_has_no_cards(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._deck = []
        controller._player1.cards = CardSet(cards=(), trump=controller._trump)
        controller._player2.cards = CardSet(
            cards=(DurakCard('KD'), DurakCard('KS')), trump=controller._trump
        )
        controller._state = controller.States.MOVING
        controller._logger_enabled = False

        controller._check_for_game_over()
        self.assertTrue(controller._state is None)
        self.assertEqual(controller._winner, controller._player1)

        controller._player1.cards = CardSet(
            cards=(DurakCard('AC'), DurakCard('8S')), trump=controller._trump
        )
        controller._player2.cards = CardSet(cards=(), trump=controller._trump)
        controller._state = controller.States.MOVING
        controller._check_for_game_over()
        self.assertTrue(controller._state is None)
        self.assertEqual(controller._winner, controller._player2)
Пример #46
0
    def test_check_for_game_over_player_wins_if_has_no_cards(self):
        controller = GameController()
        controller._trump = DurakCard('6H')
        controller._deck = []
        controller._player1.cards = CardSet(cards=(), trump=controller._trump)
        controller._player2.cards = CardSet(cards=(DurakCard('KD'),
                                                   DurakCard('KS')),
                                            trump=controller._trump)
        controller._state = controller.States.MOVING
        controller._logger_enabled = False

        controller._check_for_game_over()
        self.assertTrue(controller._state is None)
        self.assertEqual(controller._winner, controller._player1)

        controller._player1.cards = CardSet(cards=(DurakCard('AC'),
                                                   DurakCard('8S')),
                                            trump=controller._trump)
        controller._player2.cards = CardSet(cards=(), trump=controller._trump)
        controller._state = controller.States.MOVING
        controller._check_for_game_over()
        self.assertTrue(controller._state is None)
        self.assertEqual(controller._winner, controller._player2)
Пример #47
0
 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()
Пример #48
0
 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()