Question: 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 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). using a play file and a cap file with exisiting code from enum import Enum, auto
from typing import Callable
class Colour(Enum):
RED = auto()
BLUE = auto()
GREEN = auto()
YELLOW = auto()
def __str__(self)-> str:
return self.name
class Shape(Enum):
HEXAGON = auto()
CIRCLE = auto()
DIAMOND = auto()
RHOMBUS = auto()
def __str__(self)-> str:
return self.name
class Card:
def __init__(self, colour: Colour, shape: Shape, number: int):
self.colour = colour
self.shape = shape
self.number = number
def get_colour(self)-> Colour:
return self.colour
def get_shape(self)-> Shape:
return self.shape
def get_number(self)-> int:
return self.number
def __repr__(self)-> str:
return "("+ str(self.number)+","+ str(self.colour)+\
","+ str(self.shape)+")"
def __eq__(self, o)-> bool:
if not isinstance(o, Card):
return False
return self.colour is o.get_colour() and \
self.shape is o.get_shape() and \
self.number == o.get_number()
class Player:
def __init__(self, hand: list[Card]):
self.hand = hand
def __match(self, test: Callable[[Card], bool])-> int:
return len([card for card in self.hand if test(card)])
def how_many_colour(self, colour: Colour)-> int:
return self.__match(lambda x: x.get_colour() is colour)
def how_many_shape(self, shape: Shape)-> int:
return self.__match(lambda x: x.get_shape() is shape)
def how_many_number(self, number: int)-> int:
return self.__match(lambda x: x.get_number()== number)
def how_many_colour_number(self, colour: Colour, number: int)-> int:
return self.__match(lambda x: x.get_colour() is colour and
x.get_number()== number)
def how_many_shape_number(self, shape: Shape, number: int)-> int:
return self.__match(lambda x: x.get_shape() is shape and
x.get_number()== number)
def how_many_colour_shape(self, colour: Colour, shape: Shape)-> int:
return self.__match(lambda x: x.get_colour() is colour and
x.get_shape() is shape)
def has_card(self, guess: Card)-> bool:
return guess in self.hand

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!