def __init__(self, newContent=None): """init the meld: content can be either - a single string with 2 chars for every tile - a list containing such strings - another meld. Its tiles are not passed. - a list of Tile objects""" if not hasattr(self, '_fixed'): # already defined if I am from cache TileList.__init__(self, newContent) self.case = ''.join('a' if x.islower() else 'A' for x in self) self.key = TileList.key(self) if self.key not in self.cache: self.cache[self.key] = self self.cache[str(self)] = self self.isExposed = self.__isExposed() self.isConcealed = not self.isExposed self.isSingle = self.isPair = self.isChow = self.isPung = False self.isKong = self.isClaimedKong = self.isKnitted = False self.isDragonMeld = len(self) and self[0].isDragon self.isWindMeld = len(self) and self[0].isWind self.isHonorMeld = self.isDragonMeld or self.isWindMeld self.isBonus = len(self) == 1 and self[0].isBonus self.isKnown = len(self) and self[0].isKnown self.__setMeldType() self.isPungKong = self.isPung or self.isKong self.isDeclared = self.isExposed or self.isKong groups = set(x.group.lower() for x in self) if len(groups) == 1: self.group = self[0].group self.lowerGroup = self.group.lower() else: self.group = 'X' self.lowerGroup = 'x' self.isRest = False self.__staticRules = {} # ruleset is key self.__dynamicRules = {} # ruleset is key self.__staticDoublingRules = {} # ruleset is key self.__dynamicDoublingRules = {} # ruleset is key self.__hasRules = None # unknown yet self.__hasDoublingRules = None # unknown yet self.concealed = self.exposed = self.declared = self.exposedClaimed = None # to satisfy pylint self._fixed = True if len(self) < 4: TileList.__setattr__(self, 'concealed', Meld(TileList(x.concealed for x in self))) TileList.__setattr__(self, 'declared', self.concealed) TileList.__setattr__(self, 'exposed', Meld(TileList(x.exposed for x in self))) TileList.__setattr__(self, 'exposedClaimed', self.exposed) else: TileList.__setattr__(self, 'concealed', Meld(TileList(x.concealed for x in self))) TileList.__setattr__( self, 'declared', Meld( TileList([ self[0].exposed, self[1].concealed, self[2].concealed, self[3].exposed ]))) TileList.__setattr__(self, 'exposed', Meld(TileList(x.exposed for x in self))) TileList.__setattr__( self, 'exposedClaimed', Meld( TileList([ self[0].exposed, self[1].exposed, self[2].exposed, self[3].concealed ])))
def __init__(self, newContent=None): """init the meld: content can be either - a single string with 2 chars for every tile - a list containing such strings - another meld. Its tiles are not passed. - a list of Tile objects""" if not hasattr(self, '_fixed'): # already defined if I am from cache TileList.__init__(self, newContent) self.case = ''.join('a' if x.islower() else 'A' for x in self) self.key = TileList.key(self) if self.key not in self.cache: self.cache[self.key] = self self.cache[str(self)] = self self.isExposed = self.__isExposed() self.isConcealed = not self.isExposed self.isSingle = self.isPair = self.isChow = self.isPung = False self.isKong = self.isClaimedKong = self.isKnitted = False self.isDragonMeld = len(self) and self[0].isDragon self.isWindMeld = len(self) and self[0].isWind self.isHonorMeld = self.isDragonMeld or self.isWindMeld self.isBonus = len(self) == 1 and self[0].isBonus self.isKnown = len(self) and self[0].isKnown self.__setMeldType() self.isPungKong = self.isPung or self.isKong self.isDeclared = self.isExposed or self.isKong groups = set(x.group.lower() for x in self) if len(groups) == 1: self.group = self[0].group self.lowerGroup = self.group.lower() else: self.group = 'X' self.lowerGroup = 'x' self.isRest = False self.__staticRules = {} # ruleset is key self.__dynamicRules = {} # ruleset is key self.__staticDoublingRules = {} # ruleset is key self.__dynamicDoublingRules = {} # ruleset is key self.__hasRules = None # unknown yet self.__hasDoublingRules = None # unknown yet self.concealed = self.exposed = self.declared = self.exposedClaimed = None # to satisfy pylint self._fixed = True if len(self) < 4: TileList.__setattr__( self, 'concealed', Meld(TileList(x.concealed for x in self))) TileList.__setattr__(self, 'declared', self.concealed) TileList.__setattr__( self, 'exposed', Meld(TileList(x.exposed for x in self))) TileList.__setattr__(self, 'exposedClaimed', self.exposed) else: TileList.__setattr__( self, 'concealed', Meld(TileList(x.concealed for x in self))) TileList.__setattr__( self, 'declared', Meld(TileList([self[0].exposed, self[1].concealed, self[2].concealed, self[3].exposed]))) TileList.__setattr__( self, 'exposed', Meld(TileList(x.exposed for x in self))) TileList.__setattr__( self, 'exposedClaimed', Meld(TileList([self[0].exposed, self[1].exposed, self[2].exposed, self[3].concealed])))
def __setattr__(self, name, value): if (hasattr(self, '_fixed') and not name.endswith('__hasRules') and not name.endswith('__hasDoublingRules')): raise TypeError TileList.__setattr__(self, name, value)