This commit is contained in:
Andrzej Preibisz 2023-01-31 21:09:22 +01:00
commit 6c385a2282

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:
@ -89,15 +82,6 @@ def AI(hand: list, face_up: str) -> str:
else: else:
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