Пример #1
0
 def test_nob(self):
     self.assertEqual(
         1,
         score.score_hand(Card.from_str_list('Jc, 2c, Qc, 6h'),
                          Card.from_str('4c')))
     self.assertEqual(
         0,
         score.score_hand(Card.from_str_list('Jc, 2c, Qc, 6h'),
                          Card.from_str('4s')))
Пример #2
0
 def test_flush(self):
     self.assertEqual(
         5,
         score.score_hand(Card.from_str_list('ac, 2c, 9c, 7c'),
                          Card.from_str('Jc')))
     self.assertEqual(
         4,
         score.score_hand(Card.from_str_list('ac, 2c, 9c, 7c'),
                          Card.from_str('Jh')))
     self.assertEqual(
         0,
         score.score_hand(Card.from_str_list('ad, 2c, 9c, 7c'),
                          Card.from_str('Jc')))
Пример #3
0
 def test_fifteens(self):
     self.assertEqual(
         6,
         score.score_hand(Card.from_str_list('10C, QD, KH, 2H'),
                          Card.from_str('3S')))
     self.assertEqual(
         2,
         score.score_hand(Card.from_str_list('JC, 5D, 4H, 9S'),
                          Card.from_str('7S')))
     self.assertEqual(
         4,
         score.score_hand(Card.from_str_list('JC, QD, 4H, 3S'),
                          Card.from_str('AS')))
Пример #4
0
 def test_runs(self):
     self.assertEqual(
         4,
         score.score_hand(Card.from_str_list('2d,3d,4d'),
                          Card.from_str('5D')))
     self.assertEqual(
         8,
         score.score_hand(Card.from_str_list('2d,3d,4d'),
                          Card.from_str('4c')))
     self.assertEqual(
         17,
         score.score_hand(Card.from_str_list('2d,3d,4d,4c'),
                          Card.from_str('4s')))
Пример #5
0
 def test_three_of_a_kind(self):
     self.assertEqual(
         6,
         score.score_hand(Card.from_str_list('JC, JD, JH, 2H'),
                          Card.from_str('6S')))
     self.assertEqual(
         6,
         score.score_hand(Card.from_str_list('3c, 3d, 3s, qh'),
                          Card.from_str('kh')))
     self.assertEqual(
         8,
         score.score_hand(Card.from_str_list('JC, JD, JH, 2H'),
                          Card.from_str('2S')))
Пример #6
0
 def test_flush_box(self):
     self.assertEqual(
         5,
         score.score_hand(Card.from_str_list('ac,2c,9c,7c'),
                          Card.from_str('Jc'),
                          is_box=True))
     self.assertEqual(
         0,
         score.score_hand(Card.from_str_list('ac,2c,9c,7s'),
                          Card.from_str('Jc'),
                          is_box=True))
     self.assertEqual(
         0,
         score.score_hand(Card.from_str_list('ac,2c,9c,7c'),
                          None,
                          is_box=True))
Пример #7
0
    def test_complex_hands(self):
        sc, bd = score.score_hand_with_breakdown(
            Card.from_str_list('2d, 3d, 4d, 5d'), Card.from_str('5s'))
        self.assertEqual(1, len(bd['pairs']))
        self.assertEqual(2, len(bd['runs']))
        self.assertEqual(1, len(bd['flushes']))
        self.assertEqual(1, len(bd['fifteens']))
        self.assertEqual(16, sc)

        str_rep = '''Runs     : [2D, 3D, 4D, 5D], [2D, 3D, 4D, 5S]
Flushes  : [2D, 3D, 4D, 5D]
Fifteens : [2D, 3D, 5D, 5S]
Pairs    : [5D, 5S]'''

        self.assertEqual(str_rep, score.breakdown_tostring(bd))

        sc, bd = score.score_hand_with_breakdown(
            Card.from_str_list('jc, qc, kc, jd'), Card.from_str('js'))
        self.assertEqual(3, len(bd['pairs']))
        self.assertEqual(3, len(bd['runs']))
        self.assertEqual(15, sc)

        self.assertEqual(
            29,
            score.score_hand(Card.from_str_list('jc,5d,5h,5s'),
                             Card.from_str('5c')))
Пример #8
0
 def test_pairs(self):
     self.assertEqual(
         4,
         score.score_hand(Card.from_str_list('JS, JD, 6C, 2H'),
                          Card.from_str('2C')))
     self.assertEqual(
         2,
         score.score_hand(Card.from_str_list('QS, JD, 6C, 2H'),
                          Card.from_str('2C')))
     self.assertEqual(
         2,
         score.score_hand(Card.from_str_list('JS, QD, 3C, 3H'),
                          Card.from_str('4C')))
     self.assertEqual(
         4,
         score.score_hand(Card.from_str_list('JS, JD, 3C, 3H'),
                          Card.from_str('AC')))
Пример #9
0
 def attempts_for_score_v1(deck, target_score, verbose=False):
     if verbose:
         print(f'Looking for score of {target_score}')
     attempts = 1
     while True:
         deck.shuffle()
         h = deck.deal_one(4)
         t = deck.next_card()
         hs = score.score_hand(h, t)
         deck.return_cards(h)
         deck.return_card(t)
         if hs == target_score:
             if verbose:
                 print(
                     f'Found score of {target_score} after {attempts} attempts'
                 )
             break
         attempts += 1
     return attempts
Пример #10
0
    def choose_discards(self, hand, your_box):
        # for each possible set of 4 cards_deprecated in the hand
        #   find score for each possible turn card
        #   average the scores
        #   choose hand with highest average
        # this method sucks in sim mode, ok for interactive

        possible_turns = [x for x in self._deck if x not in hand]
        hand_scores = []

        for comb in itertools.combinations(hand, 4):
            scores = []
            for turn in possible_turns:
                scores.append(score.score_hand(list(comb), turn))
            hand_scores.append((comb, scores))

        best_score = 0
        best_hand = None
        for comb, average_score in [(comb, sum(scores)/len(scores)) for comb, scores in hand_scores]:
            if average_score > best_score:
                best_score = average_score
                best_hand = comb

        return [x for x in hand if x not in best_hand]
Пример #11
0
 def test_four_of_a_kind(self):
     self.assertEqual(
         12,
         score.score_hand(Card.from_str_list('QC, QD, QH, QS'),
                          Card.from_str('6S')))
Пример #12
0
 def test_pairs_no_turn(self):
     self.assertEqual(
         2, score.score_hand(Card.from_str_list('JS, JD, 6C, 2H'), None))
     self.assertEqual(
         0, score.score_hand(Card.from_str_list('QS, JD, 6C, 2H'), None))
Пример #13
0
 def test_flush_no_turn(self):
     self.assertEqual(
         4, score.score_hand(Card.from_str_list('ac, 2c, 9c, 7c'), None))