Exemple #1
0
def test_is_flush(faces, expected):
    hand_org = [PKCard(c) for c in faces]
    random.shuffle(faces)
    hand = Hands([PKCard(c) for c in faces])
    result = hand.is_flush()
    assert result == True
    assert hand.cards == hand_org
Exemple #2
0
def test_is_high_card(faces, expected):
    hand_org = [PKCard(c) for c in faces]
    random.shuffle(faces)
    hand = Hands([PKCard(c) for c in faces])
    result = hand.find_a_kind()
    assert result is None
    assert hand.cards == hand_org
Exemple #3
0
def test_PKCard_sort(all_faces):
    all_cards = [PKCard(c) for c in all_faces]
    import random
    random.shuffle(all_cards)
    all_cards.sort()
    assert [c.value() for c in all_cards] \
            == [i for i in range(2,len(ranks)+2) for s in suits]
Exemple #4
0
 def __init__(self, cards):
     if len(cards) != 5:
         raise ValueError('not 5 cards')
     self.cards = cards  #sorting 하기
     value_list = []
     for i in self.cards:
         a = PKCard(i)
         value_list.append(a.value())
     value_list.sort(reverse=True)
     list = []
     for j in value_list:
         for k in self.cards:
             if value[k[0]] == j:
                 list.append(k)
                 self.cards.remove(k)
     self.cards = list
Exemple #5
0
 def __init__(self, cards):
     if len(cards) != 5:
         raise ValueError('not 5 cards')
     card_list = []
     for card in cards:
         if isinstance(card, PKCard):
             card_list.append(card)
         else:
             card_list.append(PKCard(card))
     self.cards = card_list  #can be re-ordered afterwards
     self.ranking = None
Exemple #6
0
 def is_straight(self):
     self.cards.sort(reverse=True)
     values = [c.value() for c in self.cards]
     if values == list(range(values[0], values[0] - 5, -1)):
         return True
     if values[0] == PKCard('AS').value():
         values.pop(0)
         values.append(1)
         if values == list(range(values[0], values[0] - 5, -1)):
             ace = self.cards.pop(0)
             self.cards.append(ace)
             return True
         return False
Exemple #7
0
def test_PKCard_init_exception():
    for face in ['10S', 'BD', 'TA']:
        with pytest.raises(ValueError):
            PKCard(face)
Exemple #8
0
def cTH():
    return PKCard('TH')
Exemple #9
0
def test_PKCard_init():
    card = PKCard('AC')
    assert card.rank == 'A' and card.suit == 'C'
    assert card.card == 'AC'
Exemple #10
0
def c9H():
    return PKCard('9H')
Exemple #11
0
def c9C():
    return PKCard('9C')
Exemple #12
0
def test_PKCard_value(all_faces):
    for face in all_faces:
        card, expected = PKCard(face), PKCard.VALUES[face[0]]
        assert card.value() == expected
Exemple #13
0
def test_PKCard_repr():
    assert repr(PKCard('AC')) == 'AC'
Exemple #14
0
    def tuple(self):
        hand_ranking = [
            'straight flush', 'four of a kind', 'full house', 'flush',
            'straight', 'three of a kind', 'two pair', 'one pair', 'high card'
        ]
        s = dict(zip(hand_ranking, range(9, 0, -1)))
        if self.tell_hand_ranking() == 'one pair':  #one pair끼리 비교하기 편하게 튜플만들기
            rank_list = []
            for i in range(5):
                rank_list.append(self.cards[i][0])
            for j in rank_list:
                if rank_list.count(j) == 2:
                    onepair = j
                    break
            for x in range(5):
                if self.cards[x][0] == onepair:
                    a = self.cards.pop(x)
                    break
            self.cards.insert(0, a)  #one pair에 해당하는 카드를 맨앞으로
            for y in range(4):
                if self.cards[y + 1][0] == onepair:
                    b = self.cards.pop(y + 1)
                    break
            self.cards.insert(1, b)  #one pair에 해당하는 카드를 두번째로
            value_list = []
            for k in self.cards:
                c = PKCard(k)
                value_list.append(c.value())
            return (s['one pair'], value_list)  #rank끼리만 비교하기위한 튜플

        elif self.tell_hand_ranking(
        ) == 'two pair':  #two pair끼리 비교하기 편하게 튜플만들기
            rank_list = []
            for i in range(5):
                rank_list.append(self.cards[i][0])
            for j in rank_list:
                if rank_list.count(j) == 1:
                    not_twopair = j
                    break
            for k in range(5):
                if self.cards[k][0] == not_twopair:
                    a = self.cards.pop(k)
                    break
            self.cards.insert(4, a)  #two pair에 해당하지 않는 카드를 맨 뒤로
            value_list = []
            for l in self.cards:
                c = PKCard(l)
                value_list.append(c.value())
            return (s['two pair'], value_list)  #rank끼리만 비교하기위한 튜플

        elif self.tell_hand_ranking(
        ) == 'three of a kind':  #three of a kind끼리 비교하기 편하게 튜플만들기
            rank_list = []
            for i in range(5):
                rank_list.append(self.cards[i][0])
            for j in rank_list:
                if rank_list.count(j) == 3:
                    triple = j
                    break
            for k in range(5):
                if self.cards[k][0] == triple:
                    a = self.cards.pop(k)
                    break
            self.cards.insert(0, a)  #three of a kind에 해당하는 카드를 맨 앞으로
            value_list = []
            for l in self.cards:
                c = PKCard(l)
                value_list.append(c.value())
            return (s['three of a kind'], value_list)  #rank끼리만 비교하기위한 튜플

        elif self.tell_hand_ranking(
        ) == 'four of a kind':  #four of a kind끼리 비교하기 편하게 튜플만들기
            rank_list = []
            for i in range(5):
                rank_list.append(self.cards[i][0])
            for j in rank_list:
                if rank_list.count(j) == 1:
                    not_four = j
                    break
            for k in range(5):
                if self.cards[k][0] == not_four:
                    a = self.cards.pop(k)
                    break
            self.cards.insert(4, a)  #four of a kind에 해당하지 않는 카드를 맨 뒤로
            value_list = []
            for l in self.cards:
                c = PKCard(l)
                value_list.append(c.value())
            return (s['four of a kind'], value_list)  #rank끼리만 비교하기위한 튜플

        else:
            value_list = []
            for i in self.cards:
                c = PKCard(i)
                value_list.append(c.value())
            return (s[self.tell_hand_ranking()], value_list
                    )  ##rank끼리만 비교하기위한 튜플
Exemple #15
0
def test_eval(faces, expected):
    random.shuffle(faces)
    hand = Hands([PKCard(c) for c in faces])
    hand.eval()
    assert hand.ranking == expected