def find_straight(cards): PokerCard.cardsRank(cards) #hasStraight = False StraightList = [] prevCard = cards[0] StraightList.append(prevCard) for card in cards[1:]: #check if current one is next to prevCard if prevCard - card > 1: # current one is more than 2 notch less, straight is broken StraightList = [] StraightList.append(card) elif prevCard - card == 1: StraightList.append(card) else: #same rank, skip pass prevCard = card if len(StraightList) == 5: #found the fifth one #hasStraight = True return StraightList if ((len(StraightList) == 4) & (StraightList[0].rank == '5') & (cards[0].rank == '1')): StraightList.append(cards[0]) return StraightList return []
def find_high_card(cards): PokerCard.cardsRank(cards) try: return cards[0:5] except: print("No Cards in the List") return []
def find_two_pairs(cards): """ Find best two pairs + one highest ranked cards Parameters ---------- cards : TYPE DESCRIPTION. Returns ------- pairsHeads : TYPE DESCRIPTION. """ PokerCard.cardsRank(cards) PairsList = [] try: prevCard = cards[0] except: return [] PairsList.append(prevCard) for card in cards[1:]: #check if current one is next to prevCard if prevCard - card == 0: PairsList.append(card) break else: PairsList = [] PairsList.append(card) prevCard = card AnotherPairs = [] if len(PairsList) == 2: prevCard = cards[0] for card in cards[1:]: if ((prevCard - card == 0) & (card - PairsList[0] != 0)): AnotherPairs.append(prevCard) AnotherPairs.append(card) break else: prevCard = card TwoPairs = [] TwoPairs = TwoPairs + PairsList + AnotherPairs if len(TwoPairs) == 4: for card in cards: if ((card - PairsList[0] != 0) & (card - AnotherPairs[0] != 0)): TwoPairs.append(card) break return TwoPairs else: return []
def find_set(cards): """ Find best three cards with same rank + two highest ranked cards Parameters ---------- cards : TYPE DESCRIPTION. Returns ------- TYPE DESCRIPTION. """ PokerCard.cardsRank(cards) SetList = [] try: prevCard = cards[0] except: return [] SetList.append(prevCard) for card in cards[1:]: #check if current one is next to prevCard if prevCard - card == 0: SetList.append(card) else: SetList = [] SetList.append(card) prevCard = card if len(SetList) == 3: break if len(SetList) == 3: for card in cards: if card - SetList[0] != 0: SetList.append(card) if len(SetList) == 5: return SetList return [] else: return []
def find_pair(cards): """ Find best pair of cards + three highest ranked cards Parameters ---------- cards : TYPE DESCRIPTION. Returns ------- prevCard : TYPE DESCRIPTION. """ PokerCard.cardsRank(cards) PairsList = [] try: prevCard = cards[0] except: return [] PairsList.append(prevCard) for card in cards[1:]: #check if current one is next to prevCard if prevCard - card == 0: PairsList.append(card) break else: PairsList = [] PairsList.append(card) prevCard = card if len(PairsList) == 2: for card in cards: if card - PairsList[0] != 0: PairsList.append(card) if len(PairsList) == 5: return PairsList return [] else: return []
def find_quad(cards): """ Find best quads + one high card Parameters ---------- cards : TYPE DESCRIPTION. Returns ------- QuadList : TYPE DESCRIPTION. """ PokerCard.cardsRank(cards) QuadList = [] prevCard = cards[0] QuadList.append(prevCard) for card in cards[1:]: #check if current one is next to prevCard if prevCard - card != 0: QuadList = [] QuadList.append(card) else: QuadList.append(card) prevCard = card if len(QuadList) == 4: #found the Set break if len(QuadList) == 4: for card in cards: if card - QuadList[0] != 0: QuadList.append(card) return QuadList else: return []