Open ItIsAndrewL opened 3 years ago
smarter ace adjust
class Hand:
def __init__(self):
self.cards = [] # start with an empty list as we did in the Deck class
self.value = 0 # start with zero value
self.aces = 0 # add an attribute to keep track of aces
def add_card(self,card):
# card passed in from deck class
self.cards.append(card)
self.value += values[card.rank]
# track aces
if card.rank == 'Ace':
self.aces += 1
def adjust_for_ace(self):
# if the total value is over 21 and I still have an ace
# change ace to be a 1 instead of an 11
while self.value > 21 and self.aces:
self.value -= 10
self.aces -= 1
When the dealer has 2 aces, the incorrect value is shown in the table, but the correct decision is made. Example will be uploaded in the comments.