def draw_discards(cards, ranklist): """ Calculates the approprate card to discard for any draw-type hands. """ if len(cards) != 5: raise ValueError('Card list needs to be 5 cards for a valid discard.') suit = ev.dominant_suit(cards) suit_count = ev.count_suit(cards, suit) # Check 4 card draws first # Flush draws if suit_count == 4: return ev.strip_suits(cards, suit) # Test for open-ended straight draw(s) OESD = ev.chk_straight_draw(cards, 4, 0) if OESD is not None: return extract_discards(cards, OESD) # Test for gutshot straight draw(s) GSSD = ev.chk_straight_draw(cards, 4, 1) if GSSD is not None: return extract_discards(cards, GSSD) # Draw to high cards (J+) if card.RANKS[ranklist[2].rank] > 10: highcards = ''.join([ranklist[i].rank for i in range(3)]) return ev.strip_ranks(cards, highcards) elif card.RANKS[ranklist[1].rank] > 10: highcards = ''.join([ranklist[i].rank for i in range(2)]) return ev.strip_ranks(cards, highcards) # Draw to an Ace # We'll generally draw to an Ace over any backdoor draws. if ranklist[0].rank == 'A': return ev.strip_ranks(cards, 'A') if suit_count == 3: # Backdoor flush draw return ev.strip_suits(cards, suit) # Backdoor straight draws are pretty desparate BDSD = ev.chk_straight_draw(cards, 3, 0) if BDSD is not None: return extract_discards(cards, BDSD) # 1-gap Backdoor straight draws are truly desparate! BDSD = ev.chk_straight_draw(cards, 3, 1) if BDSD is not None: return extract_discards(cards, BDSD) # Last ditch effort - just draw to the best 2. highcards = ''.join([ranklist[i].rank for i in range(2)]) return ev.strip_ranks(cards, highcards)
def test_dominantsuit_4diffranks_returnshigherrank(self): cards = tools.convert_to_cards(['Kc', 'As', 'Jd', 'Qh']) expected = 's' result = evaluator.dominant_suit(cards) self.assertEqual(expected, result)
def test_dominantsuit_HigherSpades_returnsSpades(self): cards = tools.convert_to_cards(['Ac', 'Ks', 'As', 'Qc']) expected = 's' result = evaluator.dominant_suit(cards) self.assertEqual(expected, result)
def test_dominantsuit_1card_returnssuit(self): cards = [card.Card('A', 's')] expected = 's' result = evaluator.dominant_suit(cards) self.assertEqual(expected, result)