Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- #card_nr = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
- #suits = ["♥", "♦", "♣", "♠"]
- values = {"2" : 2 , "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8, "9" : 9, "10" : 10, "J" : 10, "Q" : 10, "K" : 10,"A" : 11}
- full_deck = ['2♥', '2♦', '2♣', '2♠', '3♥', '3♦', '3♣', '3♠', '4♥', '4♦', '4♣', '4♠', '5♥', '5♦', '5♣', '5♠', '6♥', '6♦', '6♣', '6♠', '7♥', '7♦', '7♣', '7♠', '8♥', '8♦', '8♣', '8♠', '9♥', '9♦', '9♣', '9♠', '10♥', '10♦', '10♣', '10♠', 'J♥', 'J♦', 'J♣', 'J♠', 'Q♥', 'Q♦', 'Q♣', 'Q♠', 'K♥', 'K♦', 'K♣', 'K♠', 'A♥', 'A♦', 'A♣', 'A♠']
- deck = full_deck[:]
- def deal(nr_of_cards):
- dealt_cards = []
- for i in range(nr_of_cards):
- random_index = randint(0, len(deck)-1)
- random_card = deck[random_index]
- card = deck.pop(random_index)
- dealt_cards.append(random_card)
- return dealt_cards # Returnib listina käe
- def score(hand,ace_score):
- score = 0
- for i in hand:
- card_nr = i[:-1]
- if card_nr == "A":
- card_score = 11
- new_score = score + card_score
- if new_score > 21:
- card_score = 1
- scrore += card_score
- else:
- score = new_score
- else:
- card_score = values[card_nr]
- score += card_score
- return score
- #hand_and_deck = deal(2,deck)
- #hand = hand_and_deck[0]
- #new_deck = hand_and_deck[1]
- # def deal() võtab argumendiks nr ja tagastab käe!
- def dealer_play():
- dealer_hand = deal(2)
- dealer_score = score(dealer_hand,11)
- while dealer_score < 17:
- ##################################
- d_new_card = "".join(deal(1))
- dealer_hand.append(d_new_card)
- dealer_score = score(dealer_hand,11)
- ###################################
- print("Diileri käsi: ",dealer_hand)
- print("Diileri score; ", dealer_score)
- print("______________________________")
- return dealer_score
- def play():
- player_hand = deal(2)
- print(player_hand)
- player_score = score(player_hand,11)
- print("Sinu praegune skoor on: ", player_score)
- if player_score == 21:
- print("BLACKJACK!")
- return player_score
- while input("Hit or pass") == "hit".lower():
- if player_score > 21:
- print(player_score,"Kaotasid")
- return player_score
- new_card = "".join(deal(1))
- print("Uus kaart: " , new_card)
- player_hand.append(new_card)
- print("Uus käsi: ", player_hand)
- player_score = score(player_hand,11)
- print("Sinu uus skoor: ",player_score)
- if player_score > 21 :
- print(player_score)
- return player_score
- elif player_score == 21:
- print("BLACKJACK!")
- return player_score
- print("Sinu skoor on: ", player_score) #WHILE TSÜKLIST VÄLJAS,
- return player_score
- dealerscore= dealer_play()
- player_score = play() #returnib player_score
- #if player_score > dealer_score:
- #print("Võit!")
- #else:
- #print("kaotasid")
- #print("käsi ",hand)
- #skoor = score(hand,11)
- #print(score(hand,11))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement