def auto_discard(hand, max_discards=5): """ Calculates the best discard in a 5 card hand. Takes a maximum number of allowed discards. If the auto-pick for discards is larger than the max, we will pop out the lowest cards(thereby keeping the higher and more valuable cards) until we reach the allowable number. hand is a Hand object """ _logger.debug('auto_discard for {}.'.format(hand)) ranklist = ev.rank_list(hand.cards) if hand.rank() == 'HIGH CARD': _logger.debug('Hand is a draw-type hand, finding best discard.') discards = draw_discards(sorted(hand.cards[:]), ranklist) else: _logger.debug('Hand is a made-hand, finding best discard.') discards = made_hand_discards(hand, ranklist) while len(discards) > max_discards: _logger.debug('The quantity of discards is greater than the max allowed discards.') lowcard = min(discards) _logger.debug('Pruning 1 card from the discards.') discards.remove(lowcard) _logger.debug('Returning these discards: {}.'.format(discards)) return discards
def test_ranklist_2Aces_2AcesCounted(self): cards = tools.convert_to_cards(['As', 'Ah']) ranklist = evaluator.rank_list(cards) expected_qty = ranklist[0][0] expected_rank = ranklist[0][1] self.assertTrue( expected_qty == 2, expected_rank == 'A')
def test_ranklist_1Ace_1AceCounted(self): cards = [card.Card('A', 's')] ranklist = evaluator.rank_list(cards) expected_qty = ranklist[0][0] expected_rank = ranklist[0][1] self.assertTrue( expected_qty == 1, expected_rank == 'A')
def test_ranklist_AK_lenEquals2(self): cards = tools.convert_to_cards(['As', 'Kh']) expected = 2 ranklist = evaluator.rank_list(cards) result = len(ranklist) self.assertEqual(expected, result)
def test_ranklist_1Ace_lenEquals1(self): cards = [card.Card('A', 's')] expected = 1 ranklist = evaluator.rank_list(cards) result = len(ranklist) self.assertEqual(expected, result)
def test_scoreranklist_A_return14(self): cards = [card.Card('A', 's')] expected = 14 * evaluator.MULTIPLIERS[0] rd = evaluator.rank_list(cards) result = evaluator.score_ranklist(rd) self.assertEqual(expected, result)