Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("#####################")
- print("# BlackJack #")
- print("# Matthew #")
- print("#####################")
- import random, player1
- suits = ['\u2660','\u2661','\u2662','\u2663']
- ranks = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
- def shuffledDeck():
- deck=[]
- for suit in suits:
- for rank in ranks:
- deck.append(rank+ '' +suit)
- random.shuffle(deck)
- return deck
- def dealCard(deck, hand):
- deal=deck.pop()
- hand.append(deal)
- def total(hand):
- values = {'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'1':10,
- 'J':10,'Q':10,'K':10,'A':11}
- result = 0
- numAces = 0
- for card in hand:
- result += values[card[0]]
- if card == 'A':
- numAces + 1
- return numAces
- while result > 21 and numAces>0:
- result - 10, numAces - 1
- return result
- def compareHands(house,player):
- if house > player:
- currentBet = player1.GetBet(currentBet, None, False)
- print(currentBet)
- print("you lose")
- print("___________________________")
- elif house < player:
- currentBet = player1.GetBet(currentBet, None, True)
- print(currentBet)
- print("YOU WIN")
- print("___________________________")
- elif house==21 and len(house_hand)==2 and len(player_hand)>2:
- currentBet = player1.GetBet(currentBet, None, False)
- print(currentBet)
- print("you lose")
- print("___________________________")
- elif player==21 and len(player_hand)==2 and len(house_hand)>2:
- currentBet = player1.GetBet(currentBet, None, True)
- print(currentBet)
- print("YOU WIN")
- print("___________________________")
- else:
- currentBet = player1.GetBet(currentBet, None, None)
- print(currentBet)
- print("Tie")
- print("___________________________")
- def printHand(hand):
- hand = " ".join(hand)
- return hand
- def blackjack():
- deck = shuffledDeck()
- house_hand = []
- player_hand = []
- househand =printHand(house_hand)
- playerhand = printHand(player_hand)
- for i in range(2):
- dealCard(deck, player_hand)
- dealCard(deck, house_hand)
- houseScore = total(house_hand)
- while houseScore < 17:
- dealCard(deck, house_hand)
- houseScore = total(house_hand)
- if houseScore > 21:
- househand =printHand(house_hand)
- playerhand =printHand(player_hand)
- currentBet = player1.GetBet(currentBet, None, True)
- print(currentBet)
- print("House Hand:" + househand)
- print("Player Hand:" + playerhand)
- print("House Busted")
- print("___________________________")
- return
- else:
- househand =printHand(house_hand)
- playerhand =printHand(player_hand)
- print("House Hand:" + househand)
- print("Player Hand:" + playerhand)
- playerScore = total(player_hand)
- if houseScore == 21:
- currentBet = player1.GetBet(currentBet, None, False)
- print(currentBet)
- print("House Score: " + str(houseScore))
- print ("you lose!")
- print("___________________________")
- return
- while playerScore < 21:
- print("Player Score: " + str(playerScore))
- hit = player1.HitStand(playerScore, houseScore)
- if hit == 'y':
- dealCard(deck, player_hand)
- playerScore = total(player_hand)
- playerhand =printHand(player_hand)
- print("New Player Hand:" + playerhand)
- print("House Score: " + str(houseScore))
- else:
- compareHands(houseScore, playerScore)
- return
- if playerScore == 21:
- print("Player Score: " + str(playerScore))
- compareHands(houseScore, playerScore)
- return
- else:
- currentBet = player1.GetBet(currentBet, None, False)
- print(currentBet)
- print("Player Score: " + str(playerScore))
- print("Over 21! You Lose")
- print("___________________________")
- return
- def playgame():
- for i in range(15):
- blackjack()
- playgame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement