Im trying to change this modified blackjack game to where there is no computer. A choice of either two or three players is asked with three cards dealt instead. How can I i change this current code to 1) prompt user for either 2 or 3 players(no computer), 2) have a 2 or 3 player game that works. Any idea or input is welcomed, thanks!
from random import choice as rc
def total(hand):
# how many aces in the hand
aces = hand.count(11)
# to complicate things a little the ace can be 11 or 1
# this little while loop figures it out for you
t = sum(hand)
return t
# a suit of cards in blackjack assume the following values
cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11]
total_deck = cards * 4
# there are 4 suits per deck and usually several decks
# this way you can assume the cards list to be an unlimited pool
cwin = 0 # computer win counter
pwin = 0 # player win counter
while True:
player = []
# draw 2 cards for the player to start
player.append(rc(cards))
player.append(rc(cards))
pbust = False # player busted flag
cbust = False # computer busted flag
while True:
# loop for the player's play ...
tp = total(player)
print "The player has these cards %s with a total value of %d" % (player, tp)
if tp > 31:
print "--> The player is busted!"
pbust = True
break
elif tp == 31:
print "\a BLACKJACK!!!"
break
else:
hs = raw_input("Hit or Stand/Done (h or s): ").lower()
if 'h' in hs:
player.append(rc(cards))
else:
break
while True:
# loop for the computer's play ...
comp = []
comp.append(rc(cards))
comp.append(rc(cards))
# dealer generally stands around 27 or 28
while True:
tc = total(comp)
if tc < 28:
comp.append(rc(cards))
else:
break
print "the computer has %s for a total of %d" % (comp, tc)
# now figure out who won ...
if tc > 31:
print "--> The computer is busted!"
cbust = True
if pbust == False:
print "The player wins!"
pwin += 1
elif tc > tp:
print "The computer wins!"
cwin += 1
elif tc == tp:
print "It's a draw!"
elif tp > tc:
if pbust == False:
print "The player wins!"
pwin += 1
elif cbust == False:
print "The computer wins!"
cwin += 1
break
print
print "Wins, player = %d computer = %d" % (pwin, cwin)
exit = raw_input("Press Enter (q to quit): ").lower()
if 'q' in exit:
break
print
print
print "Thanks for playing blackjack with the computer!"