'Replace string cards with int cards

Reviewed-on: #3
This commit is contained in:
Karol Idaszak 2023-01-31 21:08:47 +01:00
commit 7a4be0a924

View File

@ -10,7 +10,7 @@ def shoe(n_of_decks: int = 1) -> list:
Returns: Returns:
list: shoe- shuffled decks of cards list: shoe- shuffled decks of cards
""" """
vals = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'jack', 'queen', 'king', 'ace'] vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
suits = ['spades', 'clubs', 'hearts', 'diamonds'] suits = ['spades', 'clubs', 'hearts', 'diamonds']
deck = [] deck = []
@ -31,17 +31,10 @@ def cards_eval(hand: list) -> list:
Returns: Returns:
list: returns a list of values of the hand list: returns a list of values of the hand
""" """
evaluation = [0, 0] evaluation = [sum(hand), sum(hand)]
for value in hand: for value in hand:
if value in ['jack', 'queen', 'king']: if value == 1:
evaluation[0] += 10
evaluation[1] += 10 evaluation[1] += 10
elif value == 'ace':
evaluation[0] += 1
evaluation[1] += 11
else:
evaluation[0] += int(value)
evaluation[1] += int(value)
if evaluation[0] == evaluation[1]: if evaluation[0] == evaluation[1]:
return [evaluation[0]] return [evaluation[0]]
elif evaluation[1] > 21: elif evaluation[1] > 21:
@ -90,15 +83,6 @@ def AI(hand: list, face_up: str) -> str:
return 'stand' return 'stand'
### temp ### temp
def has_blackjack_occured(hand: list):
"""Method assumes that hand value == 21 """
if len(hand) != 2:
return False
if "ace" in hand and any([value in hand for value in ['jack', 'queen', 'king']]):
return True
return False
def show_game_state(player_hand: list, dealer_hand: list, decision: str='') -> None: def show_game_state(player_hand: list, dealer_hand: list, decision: str='') -> None:
"""Print dealer and player card values and player decision """Print dealer and player card values and player decision
@ -160,7 +144,7 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list=[], bet: int=1
show_game_state(player_hand, dealer_hand) show_game_state(player_hand, dealer_hand)
if player_value == 21 and has_blackjack_occured(player_hand): if player_value == 21 and 1 in player_hand:
return 'player blackjack', bet return 'player blackjack', bet
elif player_value > 21: elif player_value > 21:
return 'dealer win', bet return 'dealer win', bet