Python Blackjack - Count Hand of Players -


so i'm trying count hands of multiple players , compare them each other.

here's main code:

def make_deck():     # randomly shuffle deck     import random     cards = []     suit in ['h', 'c', 's', 'd']:         num in ['a', '2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q',                 'k']:             cards.append(num + suit)     random.shuffle(cards)     return cards deck = make_deck()   num_of_players = int(input("how many players?: "))  def deal_blackjack(deck, num_of_players):     # deal 2 cards number of players     hands = [[] p in range(num_of_players)]     = -1     k in range(0,2):         h in hands:             += 1             h.append(deck[i])     return hands  phands = deal_blackjack(deck, num_of_players)   def print_blackjack(phands):     # prints players respective hand     in range(len(phands)):         print('player', i, ':', phands[i])  def get_max(phands):  #where i'm stuck @     in range(phands):         total = 0          ptotal = int(phands[i][x][0]) 

i know have use phands , loop first character of each hand, , convert int ex. int(phands[i #of hand][x #of 1st str][0]) , add onto total

but can't seem figure how implement each hand of player.

ex. 4 players

player 0 : ['3s', 'jh'] total = 13

player 1 : ['6c', 'jc'] total = 16

player 2 : ['4h', '5d'] total = 9

player 3 : ['7d', 'ac'] total = 18

#

also, want compare each hand , select winner (where asterisk appears beside hand).

#

ex. 4 players

player 0 : ['3s', 'jh']

player 1 : ['6c', 'jc']

player 2 : ['4h', '5d']

player 3 : ['7d', 'ac'] *

thanks help!

you should create method called calculate_hand work in there.

scores = {"a":1, "t":10, "j": 10, "k":10, "q": 10, } def calculate_hand(hand):     hand_value = 0     ace = false     card in hand:         if card[0] == "a":             ace =true;         if card[:-1] in scores:  #used [:-1] insted of [0] because @ first, thought 10 instead of t             hand_value += scores[card[:-1]]         else:             hand_value += int(card[:-1])     if ace , hand_value + 10 < 22:         hand_value += 10     return hand_value  hand1 = ['ad', 'ac'] hand2 = ['6c', 'jc'] hand3 = ['7d', 'ac']    value1 = calculate_hand(hand1) #12 value2 = calculate_hand(hand2) #16 value3 = calculate_hand(hand3) #18 

after calculate each hand, it's simple comparing values returned calculate_hand.

print max(value1,value2,value3) #18 

you should implement these code easily.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -