Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. import random
  2. spades = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
  3. hearts = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
  4. clubs = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
  5. diamonds = ["Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"]
  6. deck = []
  7. playerHand = []
  8. dealer = []
  9. bust = 0
  10. dealBust = 0
  11. t = 0
  12.  
  13.  
  14. def assignSuit():
  15. for w in range(13):
  16. spades[w] = spades[w] + " of Spades"
  17. for x in range(13):
  18. hearts[x] = hearts[x] + " of Hearts"
  19. for y in range(13):
  20. clubs[y] = clubs[y] + " of Clubs"
  21. for z in range(13):
  22. diamonds[z] = diamonds[z] + " of Diamonds"
  23.  
  24. def shuffleDeck():
  25. global deck
  26. deck = spades + hearts + clubs + diamonds
  27. random.shuffle(deck)
  28.  
  29. def gameStart():
  30. global playerHand
  31. global dealer
  32. global deck
  33. playerHand.append(deck.pop())
  34. dealer.append(deck.pop())
  35. playerHand.append(deck.pop())
  36. dealer.append(deck.pop())
  37.  
  38. def determineCardValue():
  39. global playerHand
  40. value = 0
  41. for check in range(len(playerHand)):
  42. v = playerHand[check].partition(' ')[0]
  43. if(v=="Ace"):
  44. option = input("Would you like to value this card at 1 or 11?")
  45. value = value + option
  46. elif(v=="Two"):
  47. value = value + 2
  48. elif(v=="Three"):
  49. value = value + 3
  50. elif(v=="Four"):
  51. value = value + 4
  52. elif(v=="Five"):
  53. value = value + 5
  54. elif(v=="Six"):
  55. value = value + 6
  56. elif(v=="Seven"):
  57. value = value + 7
  58. elif(v=="Eight"):
  59. value = value + 8
  60. elif(v=="Nine"):
  61. value = value + 9
  62. else:
  63. value = value + 10
  64.  
  65. return value
  66.  
  67. def determineDealerValue():
  68. global dealer
  69. value = 0
  70. for check in range(len(dealer)):
  71. v = dealer[check].partition(' ')[0]
  72. if(v=="Ace"):
  73. if(value + 11 <= 21):
  74. value = value + 11
  75. else:
  76. value = value + 1
  77. elif(v=="Two"):
  78. value = value + 2
  79. elif(v=="Three"):
  80. value = value + 3
  81. elif(v=="Four"):
  82. value = value + 4
  83. elif(v=="Five"):
  84. value = value + 5
  85. elif(v=="Six"):
  86. value = value + 6
  87. elif(v=="Seven"):
  88. value = value + 7
  89. elif(v=="Eight"):
  90. value = value + 8
  91. elif(v=="Nine"):
  92. value = value + 9
  93. else:
  94. value = value + 10
  95.  
  96. return value
  97.  
  98. def playerTurn():
  99. global playerHand
  100. global deck
  101. global bust
  102. turn = 0
  103. while(turn==0):
  104. print "Your cards: "
  105. print playerHand
  106. choice = raw_input("Would you like to hit or stand? ")
  107. if(choice=="hit"):
  108. playerHand.append(deck.pop())
  109. if(determineCardValue()>21):
  110. print "Bust!"
  111. turn = 1
  112. bust = 1
  113. print "Your cards: "
  114. print playerHand
  115. elif(determineCardValue()==21):
  116. print "Blackjack!"
  117. turn = 1
  118. elif(choice=="stand"):
  119. turn=1
  120. print "The value you are staying at is " + str(determineCardValue()) + "."
  121. else:
  122. print "Please enter a valid choice."
  123.  
  124. def dealerTurn():
  125. global dealer
  126. global deck
  127. global dealBust
  128. turn = 0
  129. while(turn==0):
  130. if(determineDealerValue()<17):
  131. dealer.append(deck.pop())
  132. elif(determineDealerValue()>21):
  133. turn = 1
  134. dealBust = 1
  135. else:
  136. turn = 1
  137.  
  138. def determineWinner():
  139. global dealBust
  140. global bust
  141. global playerHand
  142. global dealer
  143. if(dealBust==1):
  144. if(bust==1):
  145. print "Tie!"
  146. else:
  147. print "You win!"
  148. elif(bust==1):
  149. if(dealBust==1):
  150. print "Tie!"
  151. else:
  152. print "Dealer wins!"
  153. else:
  154. if(determineCardValue()>determineDealerValue()):
  155. print "You win!"
  156. elif(determineCardValue()<determineDealerValue()):
  157. print "Dealer wins!"
  158. else:
  159. print "Tie!"
  160.  
  161. def play():
  162. global t
  163. if(t==0):
  164. assignDeck()
  165. shuffleDeck()
  166. gameStart()
  167. playerTurn()
  168. dealerTurn()
  169. determineWinner()
  170. t = t + 1
  171. else:
  172. again = raw_input("Would you like to play again?(yes/no)")
  173. if(again=="yes"):
  174. assignDeck()
  175. shuffleDeck()
  176. playerHand = []
  177. dealer = []
  178. gameStart()
  179. playerTurn()
  180. dealerTurn()
  181. determineWinner()
  182.  
  183. play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement