예제 #1
0
    def test_score_pegging_stack_no_score(self):
        stack = []
        sc, desc = score.score_pegging_stack(stack)
        self.assertEqual(0, sc)

        stack = Card.from_str_list('AC')
        sc, desc = score.score_pegging_stack(stack)
        self.assertEqual(0, sc)

        stack = Card.from_str_list('AC, 2S, 5D')
        sc, desc = score.score_pegging_stack(stack)
        self.assertEqual(0, sc)

        stack = Card.from_str_list('AC, 2S, AD')
        sc, desc = score.score_pegging_stack(stack)
        self.assertEqual(0, sc)
예제 #2
0
파일: player.py 프로젝트: ashbyp/pscratch
    def next_pegging_card(self, stack, hand, turn_card):
        stack_score = sum([x.value for x in stack])
        score_per_card = []  # tuples (score, stack_score)
        for card in hand:
            if stack_score + card.value <= 31:
                score_per_card.append((score.score_pegging_stack(stack + [card])[0], stack_score + card.value))
            else:
                score_per_card.append((None, None))

        if all(x[0] is None for x in score_per_card):
            return None

        best_score = max(x[0] for x in score_per_card if x[0] is not None)

        possible_plays = []

        for i, s in enumerate(score_per_card):
            if s[0] == best_score:
                possible_plays.append((s[1], hand[i]))

        if possible_plays:
            best_possible_plays = [x for x in possible_plays if x[0] not in (5, 21)]
            if best_possible_plays:
                return best_possible_plays[0][1]
            else:
                return possible_plays[0][1]

        return None
예제 #3
0
파일: player.py 프로젝트: ashbyp/pscratch
    def next_pegging_card(self, stack, hand, turn_card):
        stack_score = sum([x.value for x in stack])
        score_per_card = []
        for card in hand:
            if stack_score + card.value <= 31:
                score_per_card.append(score.score_pegging_stack(stack + [card])[0])
            else:
                score_per_card.append(None)

        if all(x is None for x in score_per_card):
            return None

        best_score = max(x for x in score_per_card if x is not None)

        for i, s in enumerate(score_per_card):
            if s == best_score:
                return hand[i]

        return None
예제 #4
0
 def test_score_pegging_stack_run_of_7(self):
     stack = Card.from_str_list('AD, 2D, 3S, 4H, 5H, 6H, 7C')
     sc, desc = score.score_pegging_stack(stack)
     self.assertEqual(7, sc)
예제 #5
0
 def test_score_pegging_stack_run_of_4(self):
     stack = Card.from_str_list('2D, 3S, 4H, 5H')
     sc, desc = score.score_pegging_stack(stack)
     self.assertEqual(4, sc)
예제 #6
0
 def test_score_pegging_stack_run_of_3(self):
     stack = Card.from_str_list('AC, JS, 2D, 3S, 4H')
     sc, desc = score.score_pegging_stack(stack)
     self.assertEqual(3, sc)
예제 #7
0
 def test_score_pegging_stack_4_of_a_kind(self):
     stack = Card.from_str_list('AC, 2S, 2D, 2S, 2H')
     sc, desc = score.score_pegging_stack(stack)
     self.assertEqual(12, sc)
예제 #8
0
 def score_pegging_stack(stack):
     return score.score_pegging_stack(stack)