Answered step by step
Verified Expert Solution
Link Copied!

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 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

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

Identify how culture affects appropriate leadership behavior

Answered: 1 week ago