Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The game is played as follows: the first player ( here played by the computer ) gets 3 random cards from a deck of 6

The game is played as follows:
the first player (here played by the computer) gets 3 random cards from a deck of 64 cards (one card for each possible combination of the four colours, shapes and numbers),
the second player can then ask questions how many cards the player is holding with a given property (colour, shape, number, colour and shape, colour and number or shape and number), and guess a card the first player is holding,
when the second player has guessed all the cards the first player is holding, the game ends,
the second player then gets scored on how many questions were asked, and how many incorrect card guesses were made (lower is better).
The Starting Point
You will start with a Python implementation of the functionality from the task in Part 1- note that the names of the functions have been Pythonised (it's a real word, I promise), and some possibly handy (but not essential) extra stuff has been added. This will be in its own file (cap.py) just for convenience. While we won't stop you from modifying this, it's really not a good idea. You will also have a second file (game.py) that has a main section and an empty function play.
The Task
Your job is to complete the play function so that it plays the game according to the format given below. You are welcome to add additional functions as you see fit, but remember that the tests will run the play function, so you must ensure that the game logic flows from there.
The play Function
Ignore any colouring in the text snippets below - not sure whether it will appear for everyone, but Ed currently appears to be trying to syntax highlight it.
play (as the type annotations suggest), will take a Player object as a parameter. At the point it's given to play, it should have its hand set up (this should be unsurprising considering how the Player class works). The function should return nothing. It should generate the following outputs and allow the following interactions.
Starting the game
The game should start with:
Welcome to Sleuth!
The game loop
The game will then offer a series of menu based choices to the player. All player input will be numeric. Incorrect input results in looping back to the menu to offer the choice again. Any time an invalid choice is made, display:
That is not an option, try again.
The top level menu is:
Would you like to:
1. Ask a question.
2. Guess a card.
Which option would you like?
Asking a question
If the player selects 1, the question menu is:
Which question would you like to ask?
1. How many cards with a certain colour?
2. How many cards with a certain shape?
3. How many cards with a certain number?
4. How many cards with a certain colour and number?
5. How many cards with a certain shape and number?
6. How many cards with a certain colour and shape?
Which option would you like?
Depending on which option they choose, one or two of the follow will then display (in the order suggested by the chosen question):
The colour options are:
1. RED
2. BLUE
3. GREEN
4. YELLOW
Which colour do you want?
The shape options are:
1. HEXAGON
2. CIRCLE
3. DIAMOND
4. RHOMBUS
Which shape do you want?
Enter a number from 1-4(inclusive):
This prompt output of the form:
The player has 0 cards with colour RED.
The player has 1 cards with shape HEXAGON.
The player has 2 cards with number 3.
The player has 0 cards with colour BLUE and number 1.
The player has 1 cards with shape CIRCLE and number 3.
The player has 0 cards with colour YELLOW and shape HEXAGON.
Of course these should display the result of the query to the computer player with the actual data the human player entered. Note also the incorrect grammar of the word cards. It's always cards, just so there's no tedious messing about with the declination of English nouns.
Guessing a card
If the player selects 2 from the top menu, they should be presented with the options to select a colour, shape and number in the same format as above. If the computer player has a card with those properties, display:
The player has the card (1, RED, HEXAGON).
If this is the first time the human player has guessed that card, also display:
Good guess!
If they have already tried before, display:
But you already knew that.
after indicating the computer play has that card instead.
If the computer player does not have that card in their hand, display:
The player does not have the card (2, YELLOW, DIAMOND).
Finishing the game
Once the human player has guessed the cards the computer player is holding, display:
Congratulations!
It took you 3 questions and 0 incorrect guesses.
The player's hand was: (1, RED, HEXAGON),(2, RED, HEXAGON),(3, RED, HEXAGON)
The number of questions asked, the number of incorrect guesses, and the cards in the player's hand will of course change from game to game. The cards in the player's hand should be presented in the order they were initially guessed by the human player.
Some small hints
You will need to keep a couple of variables to keep track
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

a. What aspects of the situation are under your control?

Answered: 1 week ago