From 1cca7a2415a190367a6f8e1dd57d683ac7ec7370 Mon Sep 17 00:00:00 2001 From: karoel2 Date: Tue, 31 Jan 2023 21:07:42 +0100 Subject: [PATCH] Replace string cards with int cards --- cards.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/cards.py b/cards.py index 184decc..48ad438 100644 --- a/cards.py +++ b/cards.py @@ -10,7 +10,7 @@ def shoe(n_of_decks: int = 1) -> list: Returns: 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'] deck = [] @@ -31,17 +31,10 @@ def cards_eval(hand: list) -> list: Returns: list: returns a list of values of the hand """ - evaluation = [0, 0] + evaluation = [sum(hand), sum(hand)] for value in hand: - if value in ['jack', 'queen', 'king']: - evaluation[0] += 10 + if value == 1: 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]: return [evaluation[0]] elif evaluation[1] > 21: @@ -89,15 +82,6 @@ def AI(hand: list, face_up: str) -> str: else: return 'stand' ### 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: """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) - if player_value == 21 and has_blackjack_occured(player_hand): + if player_value == 21 and 1 in player_hand: return 'player blackjack', bet elif player_value > 21: return 'dealer win', bet