Question

Python 3.7 Card Game:   In this assignment you will be creating ‘card game’ with specific rules....

Python 3.7

Card Game:  

In this assignment you will be creating ‘card game’ with specific rules. Rules of the game are fairly simple. The game will be played with 3 players, two AI players and 1 Human player.  

Rules of the game:  

1- Will have 3 players (2 AI, and 1 Human player).  

2- The cards we have for this game is three ones (1), three twos (2), and three three’s (3).  

3- Need to shuffle the cards randomly so each player will have 3 different cards at the start of the game. - Cards will be selected randomly (random number between 1 – 3), but need to make sure each player have 3 different cards at the start of the game.  

4- The program will end when the first player collect three cards with the same number.  

5- Functions, they help making and debugging programs much easier. Break the problem down into smaller portions that you can solve and implement and test them in function form. Then you will find it easier to put them together like puzzle pieces to make the final solution.  

Program Requirements:  

1- Need to generate 3 random cards with values between 1 and 3 (both included) for each player. Sample Output:  

Welcome to Card game:  

Number of players is 3 and total cards for each player are 3  

Lets shuffle the cards  

We have 2 AI players and 1 Human player  

Player 1 AI Cards: [3, 1, 2]  

Player 2 AI Cards: [1, 3, 2]  

Player 3 Human Cards: [3, 1, 2]

==================================================  

2- Now, the game will start:  

a. At each round:  

i. First player will choose a card from the second player. Now first player has 4 cards, and second player has 2 cards.  

ii. Now Second player will choose a card from third player. Now second player will have 3 cards, and third player will have 2.  

iii. Third player will take card from first player. Now third player will have 3 cards and first player will have 3 cards as well.  

b. AI players picking cards from opponent:  

i. Rules for AI Player:  

1. Generate a random number between 1-3 (both included)  

a. In case the number is 1:  

i. This means AI player will take the first card from the other opponent.  

b. In case the number is 2:  

i. This means AI player will take the second card from the other opponent.  

c. In case the number is 3:  

i. This means AI player will take the third card from the other opponent.

c. Human player picking card from opponent:  

a. Ask player which card to pick (1 for 1st card, 2 for 2nd card, and 3 for 3rd card) from opponent.  

Sample Output:  

Round : 1  

==================================================  

AI decision is : 3  

Human cards: [3, 1]  

player1 cards: [3, 1, 2, 2]  

player2_AI: [1, 3, 2]  

Human turn  

Enter 1 for card 1  

Enter 2 for card 2  

Enter 3 for card 3  

Enter your choice: 1  

Human cards: [3, 1, 1]  

player2 cards: [3, 2]  

AI decision is : 1  

player2 cards: [3, 2, 3]  

player1 cards: [1, 2, 2]  

==================================================  

d. Game will continue until one player win ( have all 3 cards the same)  

e. Once you announce the winner, need to ask the Human player if he/she wants to play again. Sample Output:  

Round : 3  

==================================================  

AI decision is : 3  

Human cards: [1, 1]  

player1 cards: [2, 2, 3, 3]  

player2_AI: [2, 3, 1]  

Human turn  

Enter 1 for card 1  

Enter 2 for card 2  

Enter 3 for card 3  

Enter your choice: 3  

Human cards: [1, 1, 1]  

player2 cards: [2, 3]  

Player3_HUMAN WON!!  

Thanks for playing  

Do you want to play again:Y/N  

y

Welcome to Card game:  

Number of players is 3 and total cards for each player are 3  

Lets shuffle the cards  

We have 2 AI players and 1 Human player  

Player 1 AI Cards: [1, 3, 2]  

Player 2 AI Cards: [3, 1, 2]  

Player 3 Human Cards: [2, 1, 3]

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

****This requires a lot of effort so please drop a like if you are satisfied with the solution****

I have satisfied all the requirements of the question and I'm providing the screenshots of output and code for your reference..

Code:

import random

human = [1, 2, 3]
player_1 = [1, 2, 3]
player_2 = [1, 2, 3]


def checkEquality(list):
    x = list[0]
    result = True
    for y in list:
        if x != y:
            result = False
    return result


while (1):
    random.shuffle(human)
    random.shuffle(player_1)
    random.shuffle(player_2)
    print("Welcome to the Card game:")
    print("Number of players is 3 and total cards for each player are 3")
    print("We have two AI players and 1 Human player")
    print("Player 1 AI Cards:", player_1)
    print("Player 2 AI Cards:", player_2)
    print("Player 3 Human Cards:", human)
    i = 1
    while (i):
        print("Round", i)
        print("=====================================")
        choice = random.randrange(1, 4)
        print("AI decision is:", choice)
        player_1.append(human.pop(choice - 1))
        print("Human Cards:", human)
        print("Player 1 Cards:", player_1)
        print("Player 2 Cards:", player_2)
        print("Human turn")
        print("Enter 1 for card 1")
        print("Enter 2 for card 2")
        print("Enter 3 for card 3")
        print("Enter your choice: ", end="")
        choice = int(input())
        human.append(player_2.pop(choice - 1))
        print("Human Cards:", human)
        print("Player 1 Cards:", player_1)
        print("Player 2 Cards:", player_2)
        choice = random.randrange(1, 4)
        print("AI decision is:", choice)
        player_2.append(player_1.pop(choice - 1))
        print("Human Cards:", human)
        print("Player 1 Cards:", player_1)
        print("Player 2 Cards:", player_2)
        if checkEquality(human):
            print("Humane Won!!")
            break
        if checkEquality(player_1):
            print("AI Player 1 Won")
            break
        if checkEquality(player_2):
            print("AI Player 2 Won")
            break
        i += 1
    print("Thanks for Playing!!")
    print("Do you want to play again:Y/N")
    choice = input()
    if choice == 'N':
        break

Output Screenshots:

Sample Run : 1

Sample Run 2:

Code Screenshot:

Add a comment
Know the answer?
Add Answer to:
Python 3.7 Card Game:   In this assignment you will be creating ‘card game’ with specific rules....
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
  • 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...

  • Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June...

    Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June 9th, 2018 @ 23:55 Percentage overall grade: 5% Penalties: No late assignments allowed Maximum Marks: 10 Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, file reading, Queues, and data structures with encapsulation. The card game War is a card game that is played with a deck of 52 cards. The goal is to be the first player to...

  • hi can you please solve this python problem for me?? Three pets live in a happy...

    hi can you please solve this python problem for me?? Three pets live in a happy house: dog, cat and a mouse. The dog often chases the cat, the cat likes to chase the mouse, however the mighty dog runs away when it sees the mouse. Develop a game which can be played by two players. The program asks the two players (player1 and player2) to choose either 1 for dog, 2 for cat, or 3 for mouse. The rules...

  • 5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may...

    5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may recognize Rock Paper Scissors Lizard Spock as a game of chance that expands on the standard Rock Paper Scissors game. It introduces two new hand signs and several more rules. The rules: • Scissors cuts Paper • Paper covers Rock • Rock crushes Lizard • Lizard poisons Spock • Spock smashes Scissors • Scissors decapitates Lizard • Lizard eats Paper • Paper disproves Spock...

  • Using Python 3.5.2 and IDLE Write the code for a modified game of the card game...

    Using Python 3.5.2 and IDLE Write the code for a modified game of the card game crazy eights (much like a game of UNO, where the card played is now on top of the deck and its number or face value is now what is playable for the next player). Write the code to be a 2 player game with any 8 card being able to input a new face value to play on the discard pile. Rules: Use a...

  • C only (not C++) Write a C program that simulates a game. There are two players...

    C only (not C++) Write a C program that simulates a game. There are two players (called Player1 and Player2). At the start of the game, each player chooses a number from 1 to 10 (cannot be the same). Then, the program will generate a random number from 1 to 10. The game ends when either Player1 or Player2 hits the number generated by the program. Display the winning message for the winner. Example output: Player 1: 6 Player 2:...

  • C++ programming: Card game Can same one help me out with a example finsih and working...

    C++ programming: Card game Can same one help me out with a example finsih and working programm ? Program the basis for a card game (as a class card game): ● A card is represented by its suit/symbol (clubs, spades, hearts, diamonds) and a value (seven, eight, nine, ten, jack, queen, king, ace). ● A deck of cards consists of a pile of 32 cards that are completely connected to four players are distributed. ● Implement the following menu: ===...

  • the card game Acey Deucey, which is also known by several other names. In general, the...

    the card game Acey Deucey, which is also known by several other names. In general, the game is played with three or more people that continue to gamble for a pot of money. The pot grows and shrinks depending on how much General description of the game ● Two cards are dealt face up to a player from a shuffled deck of cards. ○ If the face of each card is the same then the player adds $1 into the...

  • War—A Card game Playing cards are used in many computer games, including versions of such classic...

    War—A Card game Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. War:    Deal two Cards—one for the computer and one for the player—and determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is...

  • python code( using functions please)! Rules of the game: - This game requires a dice. The...

    python code( using functions please)! Rules of the game: - This game requires a dice. The goal of the game is to collect the correct number of coins to create a dollar. Players take coins based on a roll of the dice. The numbers on the dice correlate to the coin values as follows:  1—penny  2—nickel  3—dime  4—quarter  5— ( pick a random card from 1 to 4): o 1 = penny o 2 =...

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