Replace string cards with int cards
This commit is contained in:
parent
d7fb5e161d
commit
1cca7a2415
24
cards.py
24
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
|
||||
|
Loading…
Reference in New Issue
Block a user