コード例 #1
0
ファイル: test_combos.py プロジェクト: nhhuang/the-floor
 def test_triple(self):
     cards = [
         Card(13, 'S'),
         Card(2, 'H'),
         Card(2, 'D'),
         Card(13, 'D'),
         Card(13, 'C')
     ]
     assert combos.exists(cards, ('triple', 13))
     assert not combos.exists(cards, ('triple', 2))
     assert not combos.exists(cards, ('triple', 6))
コード例 #2
0
ファイル: test_combos.py プロジェクト: nhhuang/the-floor
    def test_two_pair(self):
        cards = [
            Card(13, 'S'),
            Card(13, 'D'),
            Card(13, 'C'),
            Card(2, 'H'),
            Card(2, 'C'),
            Card(3, 'H')
        ]
        assert combos.exists(cards, ('two-pair', 13, 2))
        assert not combos.exists(cards, ('two-pair', 13, 3))
        assert not combos.exists(cards, ('two-pair', 6, 2))

        with self.assertRaises(combos.IllegalCombo):
            assert combos.exists(cards, ('two-pair', 13, 13))
コード例 #3
0
ファイル: combos.py プロジェクト: nhhuang/the-floor
def exists(cards, combo):
    t = combo[0]
    r_counts = rank_counts(cards)
    s_counts = suit_counts(cards)
    if t == 'single':
        return r_counts[combo[1]] > 0
    elif t == 'pair':
        return r_counts[combo[1]] > 1
    elif t == 'two-pair':
        if combo[1] == combo[2]:
            raise IllegalCombo('Need different ranks for two-pair.')
        return r_counts[combo[1]] > 1 and r_counts[combo[2]] > 1
    elif t == 'triple':
        return r_counts[combo[1]] > 2
    elif t == 'straight':
        if combo[1] != 2 and combo[1] < 11:
            raise IllegalCombo('Illegal straight')
        for i in range(5):
            if r_counts[combo[1] + i] == 0:
                return False
        return True
    elif t == 'flush':
        return s_counts[combo[1]] > 4
    elif t == 'fullhouse':
        if combo[1] == combo[2]:
            raise IllegalCombo('Need different ranks for fullhouse.')
        return r_counts[combo[1]] > 2 and r_counts[combo[2]] > 1
    elif t == 'four-of-a-kind':
        return r_counts[combo[1]] == 4
    elif t == 'straight-flush':
        if combo[1] != 2 and combo[1] < 11:
            raise IllegalCombo('Illegal straight-flush')
        suit = combo[1]
        rank = combo[2]
        for i in range(5):
            if not cards.contains(Card(rank + i, suit)):
                return False
        return True
    else:
        raise IllegalCombo('Unknown combo name %s' % (combo[0], ))
コード例 #4
0
ファイル: liars_poker.py プロジェクト: nhhuang/the-floor
 def _json_to_cards(self, cards):
     return [Card(card[0], card[1]) for card in cards]
コード例 #5
0
ファイル: test_combos.py プロジェクト: nhhuang/the-floor
 def test_single(self):
     cards = [Card(13, 'S'), Card(2, 'H')]
     assert combos.exists(cards, ('single', 13))
     assert not combos.exists(cards, ('single', 6))
コード例 #6
0
ファイル: test_combos.py プロジェクト: nhhuang/the-floor
 def test_unknown_combo(self):
     cards = [Card(13, 'S'), Card(13, 'D')]
     with self.assertRaises(combos.IllegalCombo):
         assert combos.exists(cards, ('blah', 4))
コード例 #7
0
ファイル: test_combos.py プロジェクト: nhhuang/the-floor
 def test_pair(self):
     cards = [Card(13, 'S'), Card(2, 'H'), Card(13, 'D')]
     assert combos.exists(cards, ('pair', 13))
     assert not combos.exists(cards, ('pair', 2))
     assert not combos.exists(cards, ('pair', 6))