Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python version of sleuth: The Game ( Again ) The game is played as follows: the first player ( here played by the computer )
python version 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 using a play file and a cap file with exisiting code from enum import Enum, auto
from typing import Callable
class ColourEnum:
RED auto
BLUE auto
GREEN auto
YELLOW auto
def strself str:
return self.name
class ShapeEnum:
HEXAGON auto
CIRCLE auto
DIAMOND auto
RHOMBUS auto
def strself str:
return self.name
class Card:
def initself colour: Colour, shape: Shape, number: int:
self.colour colour
self.shape shape
self.number number
def getcolourself Colour:
return self.colour
def getshapeself Shape:
return self.shape
def getnumberself int:
return self.number
def reprself str:
return strselfnumber strselfcolour
strselfshape
def eqself o bool:
if not isinstanceo Card:
return False
return self.colour is ogetcolour and
self.shape is ogetshape and
self.number ogetnumber
class Player:
def initself hand: listCard:
self.hand hand
def matchself test: CallableCard bool int:
return lencard for card in self.hand if testcard
def howmanycolourself colour: Colour int:
return self.matchlambda x: xgetcolour is colour
def howmanyshapeself shape: Shape int:
return self.matchlambda x: xgetshape is shape
def howmanynumberself number: int int:
return self.matchlambda x: xgetnumber number
def howmanycolournumberself colour: Colour, number: int int:
return self.matchlambda x: xgetcolour is colour and
xgetnumber number
def howmanyshapenumberself shape: Shape, number: int int:
return self.matchlambda x: xgetshape is shape and
xgetnumber number
def howmanycolourshapeself colour: Colour, shape: Shape int:
return self.matchlambda x: xgetcolour is colour and
xgetshape is shape
def hascardself guess: Card bool:
return guess in self.hand
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