Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # H.A. First-release
- import random
- from collections import namedtuple
- Deck = namedtuple('Deck','DeckAndType')
- highcards = "JQKA"
- decks = list()
- def init1():
- for j in range(0,4,1):
- for i in range (2,11,1):
- if j ==0:
- temp = Deck(str(i)+" h")
- elif j==1:
- temp = Deck(str(i)+" c")
- elif j==2:
- temp= Deck(str(i)+" d")
- else:
- temp = Deck(str(i)+" s")
- decks.append(temp.DeckAndType)
- pass
- def init2():
- for z in highcards:
- temp= Deck(z+" h")
- decks.append(temp.DeckAndType)
- temp = Deck(z+" c")
- decks.append(temp.DeckAndType)
- temp = Deck(z+" d")
- decks.append(temp.DeckAndType)
- temp= Deck(z+" s")
- decks.append(temp.DeckAndType)
- pass
- selectedCards = list()
- def selected():
- index = random.randint(0,len(decks)-1)
- selectedCards.append(str(decks[index]))
- decks.pop(index)
- index = random.randint(0,len(decks)-1)
- selectedCards.append(str(decks[index]))
- decks.pop(index)
- pass
- selectedPlayerCards = list()
- def selectedPlayer():
- index = random.randint(0,len(decks)-1)
- selectedPlayerCards.append(str(decks[index]))
- decks.pop(index)
- index = random.randint(0,len(decks)-1)
- selectedPlayerCards.append(str(decks[index]))
- decks.pop(index)
- pass
- init1()
- init2()
- random.shuffle(decks)
- #print(decks)
- selected()
- selectedPlayer()
- #print(decks)
- valueP =0
- valueD =0
- print ('Player Has: '+selectedPlayerCards[0]+' '+selectedPlayerCards[1])
- print ('Dealer has: '+selectedCards[0]+' ??')
- checkValueP1 = selectedPlayerCards[0].split(" ")[0]
- checkValueP2 = selectedPlayerCards[1].split(" ")[0]
- checkValueD1 = selectedCards[0].split(" ")[0]
- checkValueD2 = selectedCards[1].split(" ")[0]
- valueP =0
- valueD =0
- def checkVal(check):
- if check == 'A':
- valueP=11
- elif check == 'K' or check =='Q' or check == 'J':
- valueP=10
- else:
- valueP = check
- return valueP
- valueP=int(checkVal(checkValueP1))+int(checkVal(checkValueP2))
- if valueP==22:
- valueP=12
- valueD=int(checkVal(checkValueD1))+int(checkVal(checkValueD2))
- if valueD==22:
- valueD=12
- print('You have: ',valueP)
- if (valueP ==21):
- print ("Player Win, player has Blackjack")
- exit()
- if (valueD ==21):
- print ("Dealer Win, Dealer has Blackjack")
- exit()
- if valueD == 21 and valueP ==21:
- print("Tie, player and dealer have BlackJack")
- value=input('C(call), S(Stay)')
- x = 2
- if value=="C":
- while True:
- index = random.randint(0,len(decks)-1)
- selectedPlayerCards.append(str(decks[index]))
- decks.pop(index)
- if checkVal(selectedPlayerCards[x].split(" ")[0]) == 11 and valueP+11>21:
- valueP = valueP+1
- valueP = valueP+int(checkVal(selectedPlayerCards[x].split(" ")[0]))
- if valueP == 21:
- print('Player draws: '+ selectedPlayerCards[x] )
- print("Player has 21.")
- if len(selectedPlayerCards)<3:
- print("You have got a BlackJack")
- value="S"
- break
- if valueP >21:
- print('Player draws: '+ selectedPlayerCards[x] )
- print('Player has',valueP)
- print('Too much! The dealer wins')
- break
- print('Player draws: '+ selectedPlayerCards[x] )
- print('Player has',valueP)
- x = x+1
- value = input('C(call),S(Stay)')
- if value == "S":
- break
- z =2
- if value=="S":
- print ('Dealer has',selectedCards[0],selectedCards[1])
- print ('Dealer has:',valueD)
- while (valueD<17):
- index = random.randint(0,len(decks)-1)
- selectedCards.append(str(decks[index]))
- decks.pop(index)
- if checkVal(selectedCards[z].split(" ")[0]) == 11 and valueD+11>21:
- valueD = valueD+1
- valueD = valueD+int(checkVal(selectedCards[z].split(" ")[0]))
- print('Dealer draws:', selectedCards[z])
- z = z+1
- print ('Dealer has:',valueD)
- if valueD > valueP and valueD <=21:
- print('Dealer Wins')
- elif valueD == valueP:
- print('Tie')
- else:
- print('Player Wins')
- print ('Remaining cards: '+str(len(decks)))
Add Comment
Please, Sign In to add comment