def turn(self, hand): while hand.total < self.limit and not hand.is_bust: hand.add_card(Card.generate())
return max(viable_totals) @property def is_bust(self): return self.total > 21 def _calc_totals(total, cards): totals = [] cards = list(cards) while cards: card = cards.pop() if card.value == 1: total += 1 totals.extend(_calc_totals(total+11, cards)) else: total += card.value totals.append(total) return totals if __name__ == "__main__": from card import Card for _ in range(4): h = Hand() for i in range(3): h.add_card(Card.generate()) print(h) print(h.total) print(h.is_bust)