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
def test_PKCard_value(all_faces): for face in all_faces: card, expected = PKCard(face), PKCard.VALUES[face[0]] assert card.value() == expected
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끼리만 비교하기위한 튜플