Engine: Card a farby/hodnoty su hashovatelne
Vlastne __eq__ rusilo zdedeny __hash__, takze karty ani enumy sa nedali pouzit ako kluce dictov a v setoch. Hash doplneny konzistentne s __eq__. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+12
@@ -19,6 +19,10 @@ class Card_colors(Enum):
|
||||
return self.name == other.name
|
||||
return NotImplemented
|
||||
|
||||
# vlastne __eq__ rusi zdedeny __hash__ -- obnovit konzistentne s __eq__
|
||||
def __hash__(self):
|
||||
return hash(self.name)
|
||||
|
||||
|
||||
class Card_values(Enum):
|
||||
C7 = 1
|
||||
@@ -51,6 +55,10 @@ class Card_values(Enum):
|
||||
return self.name == other.name
|
||||
return NotImplemented
|
||||
|
||||
# vlastne __eq__ rusi zdedeny __hash__ -- obnovit konzistentne s __eq__
|
||||
def __hash__(self):
|
||||
return hash(self.name)
|
||||
|
||||
|
||||
class Card():
|
||||
def __init__(self, color: Card_colors, value: Card_values):
|
||||
@@ -63,6 +71,10 @@ class Card():
|
||||
and self.value == other.value
|
||||
return NotImplemented
|
||||
|
||||
# vlastne __eq__ rusi zdedeny __hash__ -- obnovit konzistentne s __eq__
|
||||
def __hash__(self):
|
||||
return hash((self.color, self.value))
|
||||
|
||||
def __str__(self):
|
||||
return '{}_{}'.format(self.color.name, self.value.name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user