Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Amateur Sleuthing For the second part, we will switch to Python ( just for fun ) , and implement the game play part of Sleuth.
Amateur Sleuthing
For the second part, we will switch to Python just for fun and implement the game play part of Sleuth.
The Game Again
The game is played as follows:
the first player here played by the computer gets random cards from a deck of 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 note that the names of the functions have been Pythonised its a real word, I promise and some possibly handy but not essential extra stuff has been added. This will be in its own file cappy 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 gamepy 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:
Ask a question.
Guess a card.
Which option would you like?
Asking a question
If the player selects the question menu is:
Which question would you like to ask?
How many cards with a certain colour?
How many cards with a certain shape?
How many cards with a certain number?
How many cards with a certain colour and number?
How many cards with a certain shape and number?
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:
RED
BLUE
GREEN
YELLOW
Which colour do you want?
The shape options are:
HEXAGON
CIRCLE
DIAMOND
RHOMBUS
Which shape do you want?
Enter a number from inclusive:
This prompt output of the form:
The player has cards with colour RED.
The player has cards with shape HEXAGON.
The player has cards with number
The player has cards with colour BLUE and number
The player has cards with shape CIRCLE and number
The player has 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 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 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 YELLOW, DIAMOND
Finishing the game
Once the human player has guessed the cards the computer player is holding, display:
Congratulations!
It took you questions and incorrect guesses.
The player's hand was: RED, HEXAGON RED, HEXAGON 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started