Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following problem, We have the next code, now is there a way to visualize this instead of having it in the interpeter?

I have the following problem, We have the next code, now is there a way to visualize this instead of having it in the interpeter? and I feel like there is some error in the code, because even when I point out sets it doesnt recognize it? I may be mistaken: from enum import Enum
import random
import time
class Number(Enum):
ONE =1
TWO =2
THREE =3
class Symbol(Enum):
DIAMOND = 'diamond'
SQUIGGLE = 'squiggle'
OVAL = 'oval'
class Color(Enum):
RED = 'red'
GREEN = 'green'
PURPLE = 'purple'
class Shading(Enum):
SOLID = 'solid'
STRIPED = 'striped'
OPEN = 'open'
class SetCard:
def __init__(self, number, symbol, color, shading):
self.number = number
self.symbol = symbol
self.color = color
self.shading = shading
def is_property_equal(self, other):
return (
self.number == other.number and
self.symbol == other.symbol and
self.color == other.color and
self.shading == other.shading
)
def visualize(self):
print(f"Number: {self.number.value}, Symbol: {self.symbol.value}, Color: {self.color.value}, Shading: {self.shading.value}")
def is_set(card1, card2, card3):
return (
card1.is_property_equal(card2) and
card2.is_property_equal(card3) and
card1.is_property_equal(card3)
)
def find_all_sets(cards):
n = len(cards)
for i in range(n -2):
for j in range(i +1, n -1):
for k in range(j +1, n):
if is_set(cards[i], cards[j], cards[k]):
print("Found a SET:")
cards[i].visualize()
cards[j].visualize()
cards[k].visualize()
def play_set_game():
# Generate a deck of 81 cards
deck =[SetCard(Number(num), Symbol(sym), Color(col), Shading(shade))
for num in Number for sym in Symbol for col in Color for shade in Shading]
# Shuffle the deck and deal 12 cards
random.shuffle(deck)
table_cards = deck[:12]
while True:
# Display current cards on the table
for i, card in enumerate(table_cards, 1):
print(f"{i}.", end="")
card.visualize()
# Get user input for a potential SET
user_input = input("Enter the numbers of cards for a SET (e.g.,1510): ")
selected_cards =[table_cards[int(index)-1] for index in user_input.split()]
# Check if the selected cards form a SET
if is_set(*selected_cards):
print("Congratulations! You found a SET!")
# Remove the SET from the table and replenish with new cards
table_cards =[card for card in table_cards if card not in selected_cards]
table_cards.extend(deck[:len(selected_cards)])
random.shuffle(table_cards)
else:
print("Sorry, the selected cards do not form a SET. Try again!")
# Check if the computer found a SET
computer_set_found = False
for i in range(len(table_cards)-2):
for j in range(i +1, len(table_cards)-1):
for k in range(j +1, len(table_cards)):
if is_set(table_cards[i], table_cards[j], table_cards[k]):
print("Computer found a SET:")
table_cards[i].visualize()
table_cards[j].visualize()
table_cards[k].visualize()
computer_set_found = True
break
if not computer_set_found:
print("Computer didn't find a SET this time.")
# Wait for a predetermined time (e.g.,30 seconds)
time.sleep(0.05)
play_set_game()
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

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago