[Tutor] Still making Cribbage game, NEED HELP Please

Christopher schueler chris_schueler at hotmail.com
Thu Dec 10 03:24:01 CET 2009


I  am still working on my cribbage game.. 

 

if you want rules or an outline of the rules/project information,

it is HERE -> http://jongarvin.com/cawthra/files/ics3u/cribbage_project.pdf

 

I have attached a copy of what i have so far..

i have built a deck with 52 cards AND made a dictionary containing each card and its value such as Jacks and kings worth a value of 10.

 

I was wondering if people could give me ways to finish this project WITHOUT CLASSES because we havent learnd them yet OR could somebody right their own program for this cribbage game so i can compare or get ideas from your coding.

 

This also contains my PSUEDOCODE if anybody wants to review how i did things or what certain things do

 

 

MY CODE for Cribbage::

 

 

 

from random import*


## December 2 - Jan 20, 2010
## Last mode 8/12/09
## Program by John Dananhy, Phil Sulinski & Chris Schueler 4
## We present the Tech-Sauve Cribbage game

##Sudo Code
#Functions
    #DisplayTitle
        #Printing the rules of how to play cribbage
    #GetPlayer names
        #ask of there names and set it to a variable named Player1/2
    #Build the deck
        #loop through 52 times
            #call from two diffrent arrays holding the suite and card number
            #combined the suite and card value to create a new variable
            #append the new variable to the empty array Deck
        #return the new values
#Main Program
    #ask the user if they would like to learn to play
        #if yes print the DisplayTitle function
        #otherwise continue with the main program
    #Get the players' names from the function GetPlayer1/2
    #Creating the array holding the diffrent values of the cards (numbers)
    #Creating the array holding the diffrent suite values
        #these are the arrays that the Build_Deck function uses
    #sorts the suits in order
    #creates the various empty arrays that the program will use
    #Defining the winning value
    #Using the function Builed_Deck to build the deck
    #Player1's hand is randomly drawn from the deck and appended to the array P1hand
        #That card is removed from the deck so it won't be taken twice
    #The same is done for Player2
    #Next the top card is drawn by randomly selecting a card from the deck
    #Player1 is asked to select a card from their hand to put in the crib
        #this is repeated telling Player1 to take another card from his hand
        #These cards are appended to the array crib and removed from the Players hand
    #This is repeated for Player2
    #Print all the values to the screen

#Displays title and instructions
def DisplayTitle():
    print
    print "Welcome to Tech-Sauve Cribbage"
    print "--------------------------------------------"
    print "               Insctructions                "
    print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    print "1) Only played with two players (for now)   "
    print "2) The program starts with a full deck of 52 cards"
    print "3) Deals out 6 cards to each player with a Suit letter"
    print "4) Then asks each player what 2 cards they want to discard to the crib"
    print "5) Then the program saves the crib in a temporary deck"
    print "6) Players start showing cards to get an ammount equal to 31"
    print "7) Once all the cards have been played, program counts the score"
    print "8) Then the program will count all possible scores in each hand"
    print "   And it will add the players points to their total score"
    print "9) First player to reach a score of 121 wins the game"
#Gets players names
def GetPlayer1():
    print
    Player1 = str(raw_input("Player 1's name "))
    return Player1
def GetPlayer2():
    print
    Player2 = str(raw_input("Player 2's name "))
    return Player2
#Building the deck
def Build_Deck():
    for R in range (0,52):
        cardnumb = numbers[R]
        cardsuit = suits[R]
        card = str(numbers[R])+str(suits[R])
        #All cards are put into the deck
        Deck.append(card)
    return Deck,numbers,suits,card,cardnumb,cardsuit


##DICTIIONARY CARD VALUES
cards = {"AH" : 1,"2H" : 2,"3H" : 3,"4H" : 4,"5H" : 5,"6H" : 6,"7H" : 7,"8H" : 8,"9H":9,"10H" : 10,"JH" : 10,"QH" : 10,"KH" : 10,\
"AC" : 1,"2C" : 2,"3C" : 3,"4C" : 4,"5C" : 5,"6C" : 6,"7C" : 7,"8C" : 8,"9C":9,"10C" : 10,"JC" : 10,"QC" : 10,"KC" : 10,\
"AD" : 1,"2D" : 2,"3D" : 3,"4D" : 4,"5D" : 5,"6D" : 6,"7D" : 7,"8D" : 8,"9D":9,"10D" : 10,"JD" : 10,"QD" : 10,"KD" : 10,\
"AS" : 1,"2S" : 2,"3S" : 3,"4S" : 4,"5S" : 5,"6S" : 6,"7S" : 7,"8S" : 8,"9S":9,"10S" : 10,"JS" : 10,"QS" : 10,"KS" : 10}

 

##Variables Needed & sorts the deck
numbers = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]*4
suits = ["H","C","S","D"]*13
suits.sort()
##List of arrays used
Deck = []
P1hand = []
P1value = []
P2hand = []
P2value = []
Crib = []
CribValue = []
TCvalue = []
##Setting start scores
P1_score = 0
P2_score = 0
Winner = 121
ele = 51
##Building the deck
Deck,numbers,suits,card,cardnumb,cardsuit = Build_Deck()

##                         MAIN PROGRAM                                
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##Asks user if the user wants the menu and instructions to be displayed
L2P=str(raw_input("would you like to learn to play? Y/N"))
if L2P == "Y" or L2P == "y":
    DisplayTitle()
else:
    pass
##Calling player names
Player1=GetPlayer1()
Player2=GetPlayer2()
##Players' hands are drawn randomly from the deck
for X in range(0,6):
    Y = randint(0,ele)
    draw = Deck[Y]
    P1hand.append(draw)
    #Cards are removed from the deck, to not be chosen more than once
    Deck.pop(Y)
    ele -= 1
for X2 in range (0,6):
    Y1 = randint(0,ele)
    draw2 = Deck[Y1]
    P2hand.append(draw2)
    #Cards are removed from the deck, to not be chosen more than once
    Deck.pop(Y1)
    ele -= 1
print
##Top card is drawn randomly
Top = randint(0,39)
Topcard = Deck[Top]
print
##User chooses on which cards to add to the crib
for count in range(1,3):
    print
    P1hand.sort()
    print P1hand
    print
    print Player1
    #Updates on how many cards remain in the player's hand
    print "you have the chose from 1 - ",6-(count-1)
    option = int(raw_input("what CARD would you like to add to the crib? "))
    #Card is added to crib from player's hand
    Crib.append(P1hand[option-1])
    #Card is removed from player's hand
    P1hand.pop(option-1)
print
for c2 in range(1,3):
    print
    P2hand.sort()
    print P2hand
    print
    print Player2
    #Updates on how many cards remain in the player's hand
    print "you have the chose from 1 - ",6-(c2-1)
    option1 = int(raw_input("what CARD would you like to add to the crib? "))
    #Card is added to crib from player's hand
    Crib.append(P2hand[option1-1])
    #Card is removed from player's hand
    P2hand.pop(option1-1)
##           Assigning values to each card in each players Hand & Crib            
## This also prints each players hand and the cribs face values of each card in it
def HandCardValues(P1hand,P2hand,Crib,P1value,P2value,CribValue,Topcard,TCvalue):
    P1card_1 = P1hand[0]
    P1card_2 = P1hand[1]
    P1card_3 = P1hand[2]
    P1card_4 = P1hand[3]
    P2card_1 = P2hand[0]
    P2card_2 = P2hand[1]
    P2card_3 = P2hand[2]
    P2card_4 = P2hand[3]
    Ccard_1 = Crib[0]
    Ccard_2 = Crib[1]
    Ccard_3 = Crib[2]
    Ccard_4 = Crib[3]
    Tcard_1 = Topcard[0]
    TCvalue.append(cards[Topcard])
    P1value.append(cards[P1card_1])
    P1value.append(cards[P1card_2])
    P1value.append(cards[P1card_3])
    P1value.append(cards[P1card_4])
    P2value.append(cards[P2card_1])
    P2value.append(cards[P2card_2])
    P2value.append(cards[P2card_3])
    P2value.append(cards[P2card_4])
    CribValue.append(cards[Ccard_1])
    CribValue.append(cards[Ccard_2])
    CribValue.append(cards[Ccard_3])
    CribValue.append(cards[Ccard_4])
    return P1hand,P2hand,Crib,P1value,P2value,CribValue,Topcard,TCvalue
#Prints final variables to the screen
HandCardValues(P1hand,P2hand,Crib,P1value,P2value,CribValue,Topcard,TCvalue)
print
print Deck
print
print "The TOP CARD is ",Topcard, "with a value of ",TCvalue
print Player1,"'s Hand is ",P1hand, "with a value of ",P1value
print Player2,"'s Hand is ",P2hand, "with a value of ",P2value
print "The 4 cards in the Crib are ",Crib, "with a value of ",CribValue
 		 	   		  
_________________________________________________________________
Windows Live: Make it easier for your friends to see what you’re up to on Facebook.
http://go.microsoft.com/?linkid=9691816
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091209/32d483a9/attachment-0001.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: STAGE 1.py
URL: <http://mail.python.org/pipermail/tutor/attachments/20091209/32d483a9/attachment.asc>


More information about the Tutor mailing list