All pastes #771716 Raw Edit

Mine

public text v1 · immutable
·published 2007-11-13 04:30 UTC
rendered paste body
#Section 11, 11-12-07, A simplified version of the Soltaire game from the website.  
import random
from cards import CCard, CDeck, displayGame

my_deck = CDeck()
my_card = CCard()
my_pile = CDeck()

#shuffles the deck before the game
my_deck.shuffle()
    
#creates the card list for play in the game to put into the displayGame function
cardList = [CCard() for i in range(21)]

def gameDeal(my_deck):
    keepGoing = True
    while keepGoing:        
        my_card = my_deck.deal()
        cardList[0] = my_card
        displayGame(cardList)
        print "Card dealt from deck:", my_card.disp_card()
        gameStr = raw_input ("Choose a space to place the card (input a number 1-20): ")
        #the below makes sure that the input is a digit
        while gameStr.isdigit() != True:
            print "Not valid input. Please input a digit."
            gameStr = raw_input ("Choose a space to place the card: ")
        gameNum = int(gameStr)
        #the below makes sure input is between 1 and 20
        while gameNum <= 0 or gameNum > 20:
            print "Not a valid space.  Please choose again."
            gameStr = raw_input ("Choose a space to place the card: ")
            gameNum = int(gameStr)
        #the below makes sure the user does not place a second card in any slot
        while cardList[gameNum].get_val() != 0:
            print "Space already taken.  Please select a different space."
            gameStr = raw_input ("Choose a space to place the card: ")
            gameNum = int(gameStr)
        else:
            my_card.get_val()
            cardList[gameNum] = my_card
        flag = False
        #the below ends the game after slots 1-16 are filled
        for i in range(1,17):
            if cardList[i].get_suit() == "":
                flag = True
        if flag == True:
            continue
        else:
            keepGoing = False

gameDeal(my_deck)
displayGame(cardList)

BlackJList1 = [cardList[1].get_val(), cardList[2].get_val(), cardList[3].get_val(), cardList[4].get_val(), cardList[5].get_val()]
BlackJList2 = [cardList[6].get_val(), cardList[7].get_val(), cardList[8].get_val(), cardList[9].get_val(), cardList[10].get_val()]
BlackJList3 = [cardList[11].get_val(), cardList[12].get_val(), cardList[13].get_val()]
BlackJList4 = [cardList[14].get_val(), cardList[15].get_val(), cardList[16].get_val()]
BlackJList5 = [cardList[1].get_val(), cardList[6].get_val()]
BlackJList6 = [cardList[2].get_val(), cardList[7].get_val(), cardList[11].get_val(), cardList[14].get_val()]
BlackJList7 = [cardList[3].get_val(), cardList[8].get_val(), cardList[12].get_val(), cardList[15].get_val()]
BlackJList8 = [cardList[4].get_val(), cardList[9].get_val(), cardList[13].get_val(), cardList[16].get_val()]
BlackJList9 = [cardList[5].get_val(), cardList[10].get_val()]

def calcPoints(handList):
    result = 0
    BJscore = 0
    #searches for an Ace
    for i in handList:
        if i == 1:
            BJscore += 11
        else:
            BJscore += i
    #below fixes scores of Aces for BJscores over 21
    for card in handList:
        if BJscore > 21:
            if card == 1:
                BJscore -= 10
    #Calculates points from BJ scores
    if BJscore == 21:
        if len(handList) == 2:
            result = 10
        else:
            result = 7
    elif BJscore > 21:
        result = 0
    elif BJscore == 20:
        result = 5
    elif BJscore == 19:
        result = 4
    elif BJscore == 18:
        result = 3
    elif BJscore == 17:
        result = 2
    else:
        result = 1
        

    return result
    

PointTotal = 0
BlackJList1
PointTotal += calcPoints(BlackJList1)
BlackJList2
PointTotal += calcPoints(BlackJList2)
BlackJList3
PointTotal += calcPoints(BlackJList3)
BlackJList4
PointTotal += calcPoints(BlackJList4)
BlackJList5
PointTotal += calcPoints(BlackJList5)
BlackJList6
PointTotal += calcPoints(BlackJList6)
BlackJList7
PointTotal += calcPoints(BlackJList7)
BlackJList8
PointTotal += calcPoints(BlackJList8)
BlackJList9
PointTotal += calcPoints(BlackJList9)
print "Score is: ", PointTotal