Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. from random import randint
  2.  
  3. #card_nr = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
  4. #suits = ["♥", "♦", "♣", "♠"]
  5. 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}
  6. 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♠']
  7. deck = full_deck[:]
  8.  
  9. def deal(nr_of_cards):
  10. dealt_cards = []
  11. for i in range(nr_of_cards):
  12. random_index = randint(0, len(deck)-1)
  13. random_card = deck[random_index]
  14. card = deck.pop(random_index)
  15. dealt_cards.append(random_card)
  16.  
  17. return dealt_cards # Returnib listina käe
  18.  
  19.  
  20. def score(hand,ace_score):
  21. score = 0
  22. for i in hand:
  23. card_nr = i[:-1]
  24. if card_nr == "A":
  25. card_score = 11
  26. new_score = score + card_score
  27. if new_score > 21:
  28. card_score = 1
  29. scrore += card_score
  30. else:
  31. score = new_score
  32. else:
  33. card_score = values[card_nr]
  34. score += card_score
  35. return score
  36.  
  37.  
  38. #hand_and_deck = deal(2,deck)
  39. #hand = hand_and_deck[0]
  40. #new_deck = hand_and_deck[1]
  41. # def deal() võtab argumendiks nr ja tagastab käe!
  42. def dealer_play():
  43. dealer_hand = deal(2)
  44. dealer_score = score(dealer_hand,11)
  45. while dealer_score < 17:
  46. ##################################
  47. d_new_card = "".join(deal(1))
  48. dealer_hand.append(d_new_card)
  49. dealer_score = score(dealer_hand,11)
  50. ###################################
  51. print("Diileri käsi: ",dealer_hand)
  52. print("Diileri score; ", dealer_score)
  53. print("______________________________")
  54. return dealer_score
  55.  
  56.  
  57. def play():
  58. player_hand = deal(2)
  59. print(player_hand)
  60. player_score = score(player_hand,11)
  61. print("Sinu praegune skoor on: ", player_score)
  62. if player_score == 21:
  63. print("BLACKJACK!")
  64. return player_score
  65.  
  66. while input("Hit or pass") == "hit".lower():
  67. if player_score > 21:
  68. print(player_score,"Kaotasid")
  69. return player_score
  70. new_card = "".join(deal(1))
  71. print("Uus kaart: " , new_card)
  72. player_hand.append(new_card)
  73. print("Uus käsi: ", player_hand)
  74. player_score = score(player_hand,11)
  75. print("Sinu uus skoor: ",player_score)
  76. if player_score > 21 :
  77. print(player_score)
  78. return player_score
  79. elif player_score == 21:
  80. print("BLACKJACK!")
  81. return player_score
  82.  
  83. print("Sinu skoor on: ", player_score) #WHILE TSÜKLIST VÄLJAS,
  84. return player_score
  85.  
  86.  
  87. dealerscore= dealer_play()
  88.  
  89. player_score = play() #returnib player_score
  90.  
  91. #if player_score > dealer_score:
  92. #print("Võit!")
  93. #else:
  94. #print("kaotasid")
  95.  
  96.  
  97.  
  98.  
  99. #print("käsi ",hand)
  100. #skoor = score(hand,11)
  101. #print(score(hand,11))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement