2022-12-20 23:51:27 -05:00
|
|
|
class Player:
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.hand = []
|
|
|
|
|
|
|
|
def tally_hand(self):
|
|
|
|
cards = [card[0] for card in self.hand]
|
|
|
|
cards = ['11' if card == 'A' else card for card in cards]
|
|
|
|
scores = [10 if card in 'JQK0' else int(card) for card in cards]
|
|
|
|
return scores
|
|
|
|
|
2022-12-22 18:30:42 -05:00
|
|
|
def score(self, game):
|
|
|
|
if self.name == 'Dealer' and game.active:
|
|
|
|
score = sum(self.tally_hand()[1:])
|
|
|
|
else:
|
|
|
|
score = sum(self.tally_hand())
|
|
|
|
|
2022-12-20 23:51:27 -05:00
|
|
|
if score > 21 and 11 in self.tally_hand():
|
|
|
|
return score - 10
|
|
|
|
else:
|
|
|
|
return score
|
|
|
|
|
2022-12-22 18:30:42 -05:00
|
|
|
def bust(self, game):
|
|
|
|
if self.score(game) > 21:
|
|
|
|
return True
|
2022-12-22 04:58:31 -05:00
|
|
|
|
2022-12-22 22:32:15 -05:00
|
|
|
def blackjack(self, game):
|
|
|
|
if game.active and self.name == 'Dealer':
|
|
|
|
return False
|
|
|
|
elif self.tally_hand() in [[10,11],[11,10]]:
|
2022-12-22 18:30:42 -05:00
|
|
|
return True
|