Fixed card value logic

This commit is contained in:
2023-07-19 11:27:15 +10:00
parent 210cb37575
commit 01fb3771df
2 changed files with 17 additions and 0 deletions

View File

@@ -137,8 +137,25 @@ class Hand():
def __repr__(self) -> str:
value = 0
aces = 0
# Add static values
for card in self.hand:
if card.value == 1:
aces += 1
continue
if card.value > 10:
card.value = 10
value += card.value
# Dynamically add ace value based on ideal rules
card = 11
for _ in range(aces):
if value < 20:
card = 11
if (value + card) >= 21:
card = 1
value += card
return str(value)
def __iter__(self):