Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how can I fix the blackjack gameplay and winning conditions for multiplayer? the gameplay is all over the place, in the code that I have

how can I fix the blackjack gameplay and winning conditions for multiplayer? the gameplay is all over the place, in the code that I have here the game runs fine in singleplayer and for simulations. How can multiplayer be fixed?

import random Deck = [2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K", "A", "J", "Q", "K", "A", "J", "Q", "K", "A", "J", "Q", "K", "A"]

P1Hand = [] dealerhand = [] Mode = input("Would you like to play singleplayer(1), multplayer(2) or do a simulation(3).(Type number): ")

while Mode != "1" or "2" or "3": elif Mode == "2": print("we're going to play 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(2, 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] num_players = int(input("How many players? ")) 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 elif stayOrHit == "H": dealCard(player_hands[i]) else: print("please type H(Hit) or S(Stand)") # Check for bust if total(player_hands[i]) > 21: print(f"Player {i+1} busts!") break if total(player_hands[i]) == 21: print("Blackjack! You win!") if i == num_players - 1: dealerst = True while dealerst: print(f"Dealer has {dealerhand} for 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) # Check for bust if total(dealerhand) > 21: print("Dealer busts!") break if total(dealerhand) == 21: print("Dealer has Blackjack!, Dealer wins!") # Check for win condition for j in range(num_players): if total(player_hands[j]) > 21: print(f"Player {j+1} loses!") break elif total(dealerhand) > 21: print(f"Player {j+1} wins!") break elif total(player_hands[j]) == total(dealerhand): print("its a draw!") break elif total(player_hands[j]) > total(dealerhand): print(f"Player {j+1} wins!") break else: print(f"Player {j+1} loses!") break

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

=+ d. a professor deciding how much to prepare for class

Answered: 1 week ago

Question

=+ a. a family deciding whether to buy a new car

Answered: 1 week ago