Fixed card value logic
This commit is contained in:
17
BlackJack.py
17
BlackJack.py
@@ -137,8 +137,25 @@ class Hand():
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
value = 0
|
value = 0
|
||||||
|
aces = 0
|
||||||
|
# Add static values
|
||||||
for card in self.hand:
|
for card in self.hand:
|
||||||
|
if card.value == 1:
|
||||||
|
aces += 1
|
||||||
|
continue
|
||||||
|
if card.value > 10:
|
||||||
|
card.value = 10
|
||||||
value += card.value
|
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)
|
return str(value)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user