Example #1
0
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)
Example #2
0
 def test_stripsuits_stripMultipleSuits_allSuitsWereStripped(self):
     cards = tools.convert_to_cards(['As', 'Kc', 'Qd'])
     cards = evaluator.strip_suits(cards, ['s', 'c'])
     expected = 0
     result = evaluator.count_suit(cards, 's') + evaluator.count_suit(cards, 'c')
     self.assertEqual(expected, result)
Example #3
0
 def test_stripsuits_stripSpades_containsNoSpades(self):
     cards = tools.convert_to_cards(['As', 'Kc'])
     cards = evaluator.strip_suits(cards, 's')
     expected = 0
     result = evaluator.count_suit(cards, 's')
     self.assertEqual(expected, result)