Question

2. Write a program to play a very modified version of spades. The program will select two hands of 5 cards for a single player and the computer dealer. The hands should be chosen using a function and the random methods we discussed in class. Your function should check the cards to be sure that they have not been used in the other hand. If so, then another card will be chosen at random until a hand can be formed. After the second hand is dealt, all cards are available again. A winner of the game will be chosen based on the sum of all cards in the hand. The sum of the cards will be calculated as follows: 2, 3, 10 face value Jacks 11 Queens = 12 Kings-13 Aces 14 The suit of the cards is used as a multiplier. Spades are worth 2 times the face value giving an advantage to any hands containing spades. All other suits are worth face value only

plz type it for me

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per your requirement the below one is solution please follow it step by step

#Import the needed header
from random import randint

#Method generateHandMethod()
def generateHandMethod():

    #Initialize
    ourHand = {}
    counter = 0

    #Loop
    while counter != 10:

        #Loop
        while True:

            #Update
            suit_random = randint(1,4)
            card_random = randint(2,14)
            ourCard = (suit_random, card_random)

            #Check condition
            if not ourCard in ourHand:

                #Stop
                break

        #Update
        ourHand[ourCard] = 1
        counter += 1

    #Update
    ourHands = ourHand.keys()

    #Return
    return ourHands[:len(ourHands)/2], ourHands[len(ourHands)/2:]

#Method scoreHandMethod()
def scoreHandMethod(ourHand):

    #Initialize
    ourScore = 0

    #Loop
    for ourCard in ourHand:

        #Check condition
        if(ourCard[0] == 4):

            #Update
            ourScore += ourCard[1]*2

        #Otherwise
        else:

            #Update
            ourScore += ourCard[1]

    #Return
    return ourScore

#Method spadeMethod()
def spadeMethod():

    #Intialize
    (h1, h2) = generateHandMethod()

    #Intialize suits
    ourSuit = {}
    ourSuit[1] = "clubes"
    ourSuit[2] = "diamond"
    ourSuit[3] = "heart"
    ourSuit[4] = "spade"

    #Intialize hands  
    ourHand = {}

    #Loop
    for index in range (2, 11):

        #Initialize
        ourHand[index] = str(index)

    #Initialize
    ourHand[11] = "Jack"
    ourHand[12] = "Queen"
    ourHand[13] = "King"
    ourHand[14] = "Ace"

    #Print
    print ("Player 1 Card: ")

    #Initialize
    counter = 1

    #Loop
    for ourCard in h1:

        #Print
        print ("Card #%d: Suit: %s Card: %s" % (counter, ourSuit[ourCard[0]], ourHand[ourCard[1]]))

        #Update
        counter += 1

    #Print
    print ("Player 2 Card: ")

    #Initialize
    counter = 1

    #Loop
    for ourCard in h2:

        #Print
        print ("Card #%d: Suit: %s Card: %s" % (counter, ourSuit[ourCard[0]], ourHand[ourCard[1]]))

        #Update
        counter += 1
   
    #Initialize
    s1 = scoreHandMethod(h1)
    s2 = scoreHandMethod(h2)

    #Check condition
    if s1 > s2:

        #Print
        print ("Player 1 win")

    #Check condition
    elif s1 < s2:

        #Print
        print ("Player 2 win")

    #Otherwise
    else:

        #Print
        print ("Tie")

#Function call
spadeMethod()

#Import the needed header from random import randint #Method gene rateHandMeth d ( ) def generateHandMethod ) # Initialize ou

#Return return ourscore #Method spadeMethod() def spadeMethod ): # Initialize (hl, h2)generateHandMethod ) #Initialize suits

# Update counter += 1 # Initialize s1 scoreHandMethod (hl) s2 sco reHandMethod (h2) Check condition if sl> s2: # Print print

Add a comment
Know the answer?
Add Answer to:
plz type it for me 2. Write a program to play a very modified version of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This has to be done in Haskell only. Write a program that: Given 2 poker hands...

    This has to be done in Haskell only. Write a program that: Given 2 poker hands (5 cards) in list of tuples form (ex. hand1 = [(1,0),(2,0),(3,0),(4,0),(5,0)]). Each tuple represents a card where first number of a tuple is its value (1=Ace, 2=2,...,10=10, 11=Jack, 12=Queen, 13=King) and second number its suit (0=Clubs, 1=Diamonds, 2=Hearts, 3=Spades) so (1,0) will be Ace of Clubs, or (5,2) will be 5 of Hearts, etc. Rule website: https://www.fgbradleys.com/et_poker.asp These hands are generated by an end...

  • 1. (25 total points) Probability and card games; Recall that an ordinary decdk of playing cards...

    1. (25 total points) Probability and card games; Recall that an ordinary decdk of playing cards has 52 cards of which 13 cards are from each of the four suits hearts, diamonds, spades, and clubs. Each suit contains the cards 2 to 10, ace, jack, queen, and king. (a) (10 points) Three cards are randomly selected, without replacement, from an or- dinary deck of 52 playing cards. Compute the conditional probability that the first card selected is a spade, given...

  • This activity needs to be completed in the Python language. This program will simulate part of...

    This activity needs to be completed in the Python language. This program will simulate part of the game of Poker. This is a common gambling game comparing five-card hands against each other with the value of a hand related to its probability of occurring. This program will simply be evaluating and comparing hands, and will not worry about the details of dealing and betting. Here follow the interesting combinations of cards, organized from most common to least common: Pair --...

  • I want to have a C++ program that simulates Black jack game with 2 players using vectors along wi...

    I want to have a C++ program that simulates Black jack game with 2 players using vectors along with the betting amount. The out put must clearly show the suit and value of cards on the console which was dealt to each player and dealer. and then calculate to check who is the winner. repeat the dealing 5 times. Code should be clearly sperated into header files, .cpp files and the main.cpp that calls the functions of the respective class....

  • 7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card...

    7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...

  • Using C++ Create a Blackjack program with the following features: Single player game against the dealer....

    Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card. Face cards count as 10. Player starts with $500. Player places bet before being dealt a card in a new game. New game: Deal 2 cards to each...

  • C++ program This program involves writing a VERY simplified version of the card game War. You...

    C++ program This program involves writing a VERY simplified version of the card game War. You may know this game or not but my rules are these 1. Split the deck between player1 and player2. Only the face values matter (2-14) and not the suits 2. Each player puts a card down on the table. The higher face value wins that hand. If the card values match, you will simply indicate tie and neither player wins.The original rules would require...

  • Learning objectives 1. To implement decisions using if statements 2. To write statements using the boolean...

    Learning objectives 1. To implement decisions using if statements 2. To write statements using the boolean primitive data type. 3. To compare strings and/or characters. 4. To write loops using while or for. 5. To write functions Representing playing cards and hands of cards An individual playing card is represented as a string of two characters: • the first character is from "23456789TJQKA" and represents the rank, i.e., the number or value of the card. (Note that 10 is encoded...

  • Java programing Write a program that deals a deck of card into 4 hands – Each...

    Java programing Write a program that deals a deck of card into 4 hands – Each hand having 13 cards. The program should be doing the followings use an array to randomly select 52 cards and deal it into 4 hands. Print each hand unsorted Identify the face value of each hand and display it. You should create a class called Card, and all the methods should be defined within the card class. Hints – Import below java utility to...

  • Write a Java program to simulate Blackjack. The program should be as basic as possible while...

    Write a Java program to simulate Blackjack. The program should be as basic as possible while following the rules below. Thanks a. There is one deck of cards b. Cards are drawn randomly using (Shuffle() method) c. The value of a hand is computed by adding the values of the cards in hand d. The value of a numeric card such as four is its numerical value e. The value of a face card is 10 f. Ace is either...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT