Question
how can i fix the winning conditions that I have for blackjack for the muliplayer edition of this code? i have a singleplayer version which
how can i fix the winning conditions that I have for blackjack for the muliplayer edition of this code? i have a singleplayer version which runs fine but im stuck for coding the winners and losers for multiplayer blackjack, the aim is that if one of the players or dealer get blackjack they win, or if their final value is closer to 21 than the other players or dealer then they also win, if they have the same value at the end its a tie etc etc. here is what i have done so far with some help:
elif Mode == "2":
print("we will player multiplayer") def dealCard(turn): card = random.choice(Deck) turn.append(card) Deck.remove(card) def total(hand): total = 0 ace_11s = 0 for card in hand: if card in range(11): total += card elif card in ["J", "K", "Q"]: total += 10 else: total += 11 ace_11s += 1 while ace_11s and total > 21: total -= 10 ace_11s -= 1 return total def revealdealerhand(): if len(dealerhand) == 2: return dealerhand [0] elif len(dealerhand) > 2: return dealerhand[0], dealerhand[1] print("We will play multiplayer") num_players = int(input("How many players? (up to 3): ")) player_hands = [[] for _ in range(num_players)] for i in range(num_players): for j in range (2): dealCard(player_hands[i]) for j in range(2): dealCard(dealerhand) for i in range(num_players): player_st = True while player_st: print(f"Dealer has {revealdealerhand()} and X") for j in range(num_players): print(f"Player {j + 1} has {player_hands[j]} for total of {total(player_hands[j])}") stayOrHit = input(f"Player {i + 1}: S: Stay H: Hit ") if stayOrHit == "S": player_st = False else: dealCard(player_hands[i]) if total(player_hands[i]) > 21: print(f"Player {i} busts! you lose!") break if i == num_players - 1: dealerSt = True while dealerSt: print(f"Dealer has {dealerhand} for a total of {total(dealerhand)}") for j in range(num_players): print(f"Player {j + 1} has {player_hands[j]} for total of {total(player_hands[j])}") if total(dealerhand) > 16: dealerSt = False else: dealCard(dealerhand) if total(dealerhand) > 21: print("Dealer busts!") break if total(player_hands[j]) > 21: print(f"Player {j+1} loses!") elif total(dealerhand) > 21: print(f"Player {j+1} wins!") elif total(player_hands[j]) == 21: print(f"Blackjack, you win! Player {j+1} wins!") elif total(dealerhand) == 21: print("Blackjack, the dealer wins!, you lose!") elif total(player_hands[j]) == total(dealerhand): print("Tie!") elif total(player_hands[j]) > total(dealerhand): print(f"Player {j+1} wins!") else: print(f"Player {j+1} loses!")
any help is greatly appreciated thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started