Note that you don't need the class attributes. This becomes more important when you get to the Board
, where you have a mutable class attribute that you then treat as if it were an instance attribute. This would get you into trouble if you tried to create more than one board at a time, see e.g. How do I avoid having class data shared among instances? How do I avoid having class data shared among instances?
Note that you don't need the class attributes. This becomes more important when you get to the Board
, where you have a mutable class attribute that you then treat as if it were an instance attribute. This would get you into trouble if you tried to create more than one board at a time, see e.g. How do I avoid having class data shared among instances?
Note that you don't need the class attributes. This becomes more important when you get to the Board
, where you have a mutable class attribute that you then treat as if it were an instance attribute. This would get you into trouble if you tried to create more than one board at a time, see e.g. How do I avoid having class data shared among instances?
def __init__(self, tall, black, circle, solid_top):
...
@classmethod
def from_int(selfcls, attributes):
return cls(attributes & 0b0001, ...)
def __init__(self, tall, black, circle, solid_top):
...
@classmethod
def from_int(self, attributes):
return cls(attributes & 0b0001, ...)
def __init__(self, tall, black, circle, solid_top):
...
@classmethod
def from_int(cls, attributes):
return cls(attributes & 0b0001, ...)
class Piece():
"""..."""
def __init__(self, attributes):
self.tall = attributes & 0b0001
self.black = attributes & 0b0010
self.circle = attributes & 0b0100
self.solid_top = attributes & 0b1000
@property
def full_name(self):
return ' '.join([
'Tall' if self.tall else 'Short',
'black' if self.black else 'white',
'circle' if self.circle else 'square',
'solid-top' if self.solid_top else 'hollow-top',
])
@property
def abbreviation(self):
return ''.join([
'T' if self.tall else 'S',
'W''B' if self.black else 'W',
'C' if self.circle else 'Q',
'D' if self.solid_top else 'H',
])
class Piece():
"""..."""
def __init__(self, attributes):
self.tall = attributes & 0b0001
self.black = attributes & 0b0010
self.circle = attributes & 0b0100
self.solid_top = attributes & 0b1000
@property
def full_name(self):
return ' '.join([
'Tall' if self.tall else 'Short',
'black' if self.black else 'white',
'circle' if self.circle else 'square',
'solid-top' if self.solid_top else 'hollow-top',
])
@property
def abbreviation(self):
return ''.join([
'T' if self.tall else 'S',
'W' if self.black else 'W',
'C' if self.circle else 'Q',
'D' if self.solid_top else 'H',
])
class Piece():
"""..."""
def __init__(self, attributes):
self.tall = attributes & 0b0001
self.black = attributes & 0b0010
self.circle = attributes & 0b0100
self.solid_top = attributes & 0b1000
@property
def full_name(self):
return ' '.join([
'Tall' if self.tall else 'Short',
'black' if self.black else 'white',
'circle' if self.circle else 'square',
'solid-top' if self.solid_top else 'hollow-top',
])
@property
def abbreviation(self):
return ''.join([
'T' if self.tall else 'S',
'B' if self.black else 'W',
'C' if self.circle else 'Q',
'D' if self.solid_top else 'H',
])