mardi 12 juin 2018

Always a tie with 20 points, Blackjack

The program is supposed to have a user draw for 2 cards, then a computer selection. I want it so that if the card ends up being a face card it sets the value to ten and Aces get set to a user input of either 1 or 11. Currently it will draw 2 cards and regardless of outcome the both computer and user get a tie score of 20.

import random
import easygui

card_total = 0
ace_value = 0

#List of cards
cards = {2,3,4,5,6,7,8,9,10,12,13,14,15}
card1, card2 = random.sample(cards,2)
#list of suits
suits = ['Clubs', 'Hearts', 'Spades', 'Diamonds']
suit1, suit2 = random.sample(suits, 2)
#converts number to face card name
if card1 == 12:
    card1 = 'Jack'
if card1 == 13:
    card1 = 'Queen'
if card1 == 14:
    card1 = 'King'
if card1 == 15:
    card1 = 'Ace'

if card2 == 12:
    card2 = 'Jack'
if card2 == 13:
    card2 = 'Queen'
if card2 == 14:
    card2 = 'King'
if card2 == 15:
    card2 = 'Ace'
#displays cards
first_card = ("your first card is the {} of {}") .format(card1,suit1)
second_card = ("your second card is the {} of {}") .format(card2,suit2)
print (first_card)
print (second_card)

#If draw is a face card set card value to ten
if card1 == 'Jack' or 'Queen' or 'King':
    card1 = 10
if card2 == 'Jack' or 'Queen' or 'King':
    card2 = 10
#If draw is an ace allow user to select value of ace
if card1 == 'Ace':
    ace_value = easygui.buttonbox('Do you want your ace value to be 1 or 11?','Blackjack',(1,11))
    card1 = ace_value

if card2 == 'Ace':
    ace_value = easygui.buttonbox('Do you want your ace value to be 1 or 11?','Blackjack',(1,11))
    card2 = ace_value

card_total = card1 + card2

#-------------------------------------------------------------------------
comp_list = [1,11]

comp_cards = {2,3,4,5,6,7,8,9,10,12,13,14,15}
comp_card1, comp_card2 = random.sample(comp_cards,2)

#converts number to face card name
if comp_card1 == 12:
    comp_card1 = 'Jack'
if comp_card1 == 13:
    comp_card1 = 'Queen'
if comp_card1 == 14:
    comp_card1 = 'King'
if comp_card1 == 15:
    comp_card1 = 'Ace'

if comp_card2 == 12:
    comp_card2 = 'Jack'
if comp_card2 == 13:
    comp_card2 = 'Queen'
if comp_card2 == 14:
    comp_card2 = 'King'
if comp_card2 == 15:
    comp_card2 = 'Ace'

if comp_card1 == 'Jack' or 'Queen' or 'King':
    comp_card1 = 10
if comp_card2 == 'Jack' or 'Queen' or 'King':
    comp_card2 = 10

#If draw is an ace computer randomly selects value
if comp_card1 == 'Ace':
    comp_ace_value = random.choice(comp_list)
    comp_card1 = comp_ace_value

if comp_card2 == 'Ace':
    comp_ace_value = random.choice(comp_list)
    comp_card2 = comp_ace_value

comp_select = comp_card1 + comp_card2
#-------------------------------------------------------------------------
print("##############################")
print("Your total is {}") .format(card_total)
print("Dealer total is {}") .format(comp_select)
#-------------------------------------------------------------------------
#Now begin Processing of game rules

if card_total > 21:
    print("You're bust! GAME OVER")
    exit()

if comp_select > 21:
    print("Dealer has gone over! You Win!")
    exit()

if card_total > comp_select and card_total <= 21:
    print("You have beaten the dealer! You Win!")

if card_total < comp_select and comp_select <= 21:
    print("You have been beaten!")

if card_total == comp_select:
    print("Tie game!")




Aucun commentaire:

Enregistrer un commentaire