예제 #1
0
    def test_melding_3(self):  # 2020-Apr-19
        hand_text = [
            '7H', '6H', '5H', '4S', '4H', '3H', '2S', 'AS', 'AH', 'AD', 'AC'
        ]
        hand = [utils.card_from_text(x) for x in hand_text]
        going_out_deadwood_count = 10
        knock_cards, gin_cards = judge.get_going_out_cards(
            hand=hand, going_out_deadwood_count=going_out_deadwood_count)

        player = GinRummyPlayer(player_id=0, np_random=np.random.RandomState())
        player.hand = hand
        player.did_populate_hand()
        meld_clusters = player.get_meld_clusters()
        alpha, beta = judge._get_going_out_cards(
            meld_clusters=meld_clusters,
            hand=hand,
            going_out_deadwood_count=going_out_deadwood_count)
        self.assertEqual(set(alpha), set(knock_cards))
        self.assertEqual(beta, [])

        correct_knock_cards = [
            utils.card_from_text(x)
            for x in ['7H', '4S', '4H', '3H', '2S', 'AS', 'AH', 'AD', 'AC']
        ]
        self.assertEqual(set(knock_cards), set(correct_knock_cards))
        self.assertEqual(gin_cards, [])
예제 #2
0
    def test_melding_3(self):  # 2020-Apr-19
        hand_text = [
            '7H', '6H', '5H', '4S', '4H', '3H', '2S', 'AS', 'AH', 'AD', 'AC'
        ]
        hand = [utils.card_from_text(x) for x in hand_text]
        going_out_deadwood_count = 10
        knock_cards, gin_cards = judge.get_going_out_cards(
            hand=hand, going_out_deadwood_count=going_out_deadwood_count)

        player = GinRummyPlayer(player_id=0)
        player.hand = hand
        player.did_populate_hand()
        meld_clusters = player.get_meld_clusters()
        alpha, beta = judge._get_going_out_cards(
            meld_clusters=meld_clusters,
            hand=hand,
            going_out_deadwood_count=going_out_deadwood_count)
        assert set(alpha) == set(knock_cards)
        assert beta == []

        correct_knock_cards = [
            utils.card_from_text(x)
            for x in ['7H', '4S', '4H', '3H', '2S', 'AS', 'AH', 'AD', 'AC']
        ]
        assert set(knock_cards) == set(correct_knock_cards)
        assert gin_cards == []
예제 #3
0
 def test_knocking(self):
     hand_text = [
         'JS', 'JH', 'JD', '8C', '7S', '7H', '7D', '4S', '3D', '2S', 'AC'
     ]
     hand = [utils.card_from_text(x) for x in hand_text]
     knock_cards, _ = judge.get_going_out_cards(hand=hand,
                                                going_out_deadwood_count=10)
     self.assertEqual(set(knock_cards),
                      set([utils.card_from_text(x) for x in ['8C']]))
예제 #4
0
    def test_melding(self):
        hand_text = [
            '9H', 'AC', 'TH', '3C', '3D', '7C', 'QH', '3H', '8C', '8D', '4D',
            '7H', '8S', '5H', '4H', 'AS', 'TD', '3S', '2S', 'AH'
        ]
        hand = [utils.card_from_text(x) for x in hand_text]

        # check
        all_set_melds_text = [['3C', '3D', '3H', '3S'], ['8C', '8D', '8S'],
                              ['AC', 'AS', 'AH'], ['3D', '3H', '3S'],
                              ['3C', '3H', '3S'], ['3C', '3D', '3S'],
                              ['3C', '3D', '3H']]
        all_set_melds_text = set([frozenset(x) for x in all_set_melds_text])
        all_set_melds = get_all_set_melds(hand)
        self.assertEqual(
            all_set_melds_text,
            set([
                frozenset([str(card) for card in meld_pile])
                for meld_pile in all_set_melds
            ]))

        # check
        all_run_melds_text = [['AS', '2S', '3S'], ['3H', '4H', '5H']]
        all_run_melds = get_all_run_melds(hand)
        self.assertEqual(all_run_melds_text,
                         [[str(card) for card in meld_pile]
                          for meld_pile in all_run_melds])

        # check
        meld_clusters = get_meld_clusters(hand=hand)
        self.assertEqual(len(meld_clusters), 36)
예제 #5
0
 def test_get_meld_piles_with_discard_card(self):
     hand_text = [
         '8D', '7D', '6S', '5H', '5C', '4C', '4S', '2S', 'AC', 'AH'
     ]
     hand = [utils.card_from_text(x) for x in hand_text]
     discard_card = utils.card_from_text('6D')
     thinker = Thinker(hand=hand)
     meld_piles_with_discard_card = thinker.get_meld_piles_with_discard_card(
         discard_card=discard_card)
     result_as_set = frozenset([
         frozenset(meld_pile) for meld_pile in meld_piles_with_discard_card
     ])
     correct_result = [[
         utils.card_from_text(x) for x in ['8D', '7D', '6D']
     ]]
     correct_result_as_set = frozenset(
         [frozenset(meld_pile) for meld_pile in correct_result])
     self.assertEqual(result_as_set, correct_result_as_set)