choose number of decks

This commit is contained in:
Adam 2022-12-11 01:15:50 -05:00
parent 0e7f293204
commit 240b0339bf

View file

@ -78,6 +78,9 @@ def make_card(vs, style):
return card_part return card_part
def generate_deck(n_decks): def generate_deck(n_decks):
n_decks = int(n_decks)
if n_decks > 8:
n_decks = 8
suits = '♠♥♦♣' suits = '♠♥♦♣'
cards = 'A234567890JQK' cards = 'A234567890JQK'
deck = [] deck = []
@ -88,13 +91,9 @@ def generate_deck(n_decks):
return deck return deck
def draw_card(player): def draw_card(player):
global players
global play_deck
players.get(player).append(play_deck.pop(random.choice(range(len(play_deck))))) players.get(player).append(play_deck.pop(random.choice(range(len(play_deck)))))
def print_hand(player): def print_hand(player):
global players
global game_active
player_cards = [make_card(card,'card_part') for card in players.get(player)] player_cards = [make_card(card,'card_part') for card in players.get(player)]
if player == 'Dealer' and game_active == True: if player == 'Dealer' and game_active == True:
player_cards[0] = make_card('na','hidden_part') player_cards[0] = make_card('na','hidden_part')
@ -108,13 +107,11 @@ def print_hand(player):
print(carriage) print(carriage)
def deal(): def deal():
global players
for i in range(2): for i in range(2):
for player in players: for player in players:
draw_card(player) draw_card(player)
def show_board(): def show_board():
global players
print('\033c', end='') print('\033c', end='')
print(title) print(title)
for player in players: for player in players:
@ -123,22 +120,20 @@ def show_board():
print_hand(player) print_hand(player)
def score_hand(player): def score_hand(player):
global players
hand = [card[0] for card in players.get(player)] hand = [card[0] for card in players.get(player)]
if hand == ['0','1'] or hand == ['1','0']:
game_active = False
gameover = player, 'has blackjack!'
return [21]
hand = ['1' if card == 'A' else card for card in hand] hand = ['1' if card == 'A' else card for card in hand]
scores = [10 if card in 'JQK0' else int(card) for card in hand] scores = [10 if card in 'JQK0' else int(card) for card in hand]
return scores return scores
def player_score(player): def player_score(player):
global players
global game_active
global gameover
card_scores = score_hand(player) card_scores = score_hand(player)
if len(card_scores) == 2 and sum(card_scores) == 11:
game_active = False
gameover = player, 'has blackjack!'
if sum(card_scores) < 11: if sum(card_scores) < 11:
if 1 in card_scores: if 1 in card_scores:
@ -152,14 +147,12 @@ def player_score(player):
return sum(card_scores) return sum(card_scores)
def main(): def main():
global kill
global players global players
global play_deck global play_deck
global game_active global game_active
global gameover global gameover
gameover = 'Error' gameover = 'Error'
num_decks = 1
# 1-8 decks # 1-8 decks
if len(play_deck) < 4: if len(play_deck) < 4:
@ -210,10 +203,11 @@ def main():
gameover = 'Bust!' gameover = 'Bust!'
game_active = False game_active = False
kill = False kill = False
play_deck = [] play_deck = []
num_decks = input('How many decks? (1-8): ')
while kill == False: while kill == False:
main() main()
if gameover == 'q': if gameover == 'q':