Advertisement
dvdg6566

Untitled

May 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. from numpy import random
  2. # 0 is win, -2 is lose, -1 is draw
  3. bustscore = -1
  4. cards = player = house = []
  5. pres = hres = [0]
  6.  
  7. def pscore():return pres[-1]
  8. def hscore(): return hres[-1]
  9.  
  10. def start(busts):
  11.     global player,house,cards,bustscore,pres,hres
  12.     bustscore = busts
  13.     player = []
  14.     cards = []
  15.     house = []
  16.     hres = [0]
  17.     pres = [0]
  18.     cards = 4*[i for i in range(1,14)]
  19.     random.shuffle(cards)
  20.  
  21.     for i in range(2):
  22.         x = hit()
  23.         if x == 0 or x == -2:
  24.             return x
  25.         x = dealer()
  26.         if x != None:
  27.             return x
  28.  
  29.     res = player + [house[0]]
  30.     return res
  31.  
  32. def hit():
  33.     global player,house,cards,bustscore,pres,hres
  34.     x = cards.pop()
  35.     player.append(min(10,x))
  36.     pres = [i+min(x,10) for i in pres]
  37.     if x == 1:
  38.         pres.extend([i+10 for i in pres])
  39.         pres.sort()
  40.     while len(pres) != 0:
  41.         if pres[-1] > bustscore:
  42.             pres.pop()
  43.         elif pres[-1] == bustscore:
  44.             return 0 #Win
  45.         else:
  46.             break
  47.  
  48.     if (len(pres) == 0):
  49.         return -2 #Lose
  50.     return x
  51.  
  52. def dealer():
  53.     global player,house,cards,bustscore,pres,hres
  54.     x = hres[-1]
  55.     y = pres[-1]
  56.     if x >= bustscore-4 and x > y:
  57.         return -2 #Dealer wins
  58.     if x >= bustscore-4 and x == y:
  59.         return -1 #Draw
  60.     d = cards.pop()
  61.     house.append(min(10,d))
  62.     hres = [i + min(10,d) for i in hres]
  63.     if (d == 1):
  64.         hres.extend([i+10 for i in hres])
  65.     while len(hres) != 0:
  66.         if hres[-1] > bustscore:
  67.             hres.pop()
  68.         elif hres[-1] == bustscore:
  69.             return -2 #Dealer Blackjack
  70.         else:
  71.             break
  72.     if len(hres) == 0:
  73.         return 0 #player Wins
  74.     return None
  75.  
  76. def stand():
  77.     global player,house,cards,bustscore,pres,hres
  78.     while True:
  79.         x = dealer()
  80.         if x != None:
  81.             return x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement