예제 #1
0
 def __sub__(self, other):
     """self - other"""
     result = self.copy()
     for key, value in other.items():
         result[key] -= value
     for key in defaultdict.keys(result):
         if result[key] == 0:
             del result[key]
     return result
예제 #2
0
파일: game.py 프로젝트: ospalh/kajongg-fork
 def _endWallDangerous(self):
     """if end of living wall is reached, declare all invisible tiles as dangerous"""
     if len(self.wall.living) <=5:
         allTiles = [x for x in defaultdict.keys(elements.occurrence) if x[0] not in 'fy']
         # see http://www.logilab.org/ticket/23986
         invisibleTiles = set(x for x in allTiles if x not in self.visibleTiles)
         msg = m18n('Short living wall: Tile is invisible, hence dangerous')
         self.dangerousTiles = list(x for x in self.dangerousTiles if x[1] != msg)
         self.dangerousTiles.append((invisibleTiles, msg))
예제 #3
0
 def findDangerousTiles(self):
     """update the list of dangerous tile"""
     pName = self.localName
     dangerous = list()
     expMeldCount = len(self._exposedMelds)
     if expMeldCount >= 3:
         if all(x in elements.greenHandTiles for x in self.visibleTiles):
             dangerous.append(
                 (elements.greenHandTiles,
                  i18n('Player %1 has 3 or 4 exposed melds, all are green',
                       pName)))
         group = list(defaultdict.keys(self.visibleTiles))[0].group
         # see https://www.logilab.org/ticket/23986
         assert group.islower(), self.visibleTiles
         if group in Tile.colors:
             if all(x.group == group for x in self.visibleTiles):
                 suitTiles = set([Tile(group, x) for x in Tile.numbers])
                 if self.visibleTiles.count(suitTiles) >= 9:
                     dangerous.append(
                         (suitTiles,
                          i18n('Player %1 may try a True Color Game',
                               pName)))
             elif all(x.value in Tile.terminals for x in self.visibleTiles):
                 dangerous.append(
                     (elements.terminals,
                      i18n('Player %1 may try an All Terminals Game',
                           pName)))
     if expMeldCount >= 2:
         windMelds = sum(self.visibleTiles[x] >= 3 for x in elements.winds)
         dragonMelds = sum(self.visibleTiles[x] >= 3
                           for x in elements.dragons)
         windsDangerous = dragonsDangerous = False
         if windMelds + dragonMelds == expMeldCount and expMeldCount >= 3:
             windsDangerous = dragonsDangerous = True
         windsDangerous = windsDangerous or windMelds >= 3
         dragonsDangerous = dragonsDangerous or dragonMelds >= 2
         if windsDangerous:
             dangerous.append((set(x for x in elements.winds
                                   if x not in self.visibleTiles),
                               i18n('Player %1 exposed many winds', pName)))
         if dragonsDangerous:
             dangerous.append((set(x for x in elements.dragons
                                   if x not in self.visibleTiles),
                               i18n('Player %1 exposed many dragons',
                                    pName)))
     self.dangerousTiles = dangerous
     if dangerous and Debug.dangerousGame:
         self.game.debug('dangerous:%s' % dangerous)
예제 #4
0
 def _endWallDangerous(self):
     """if end of living wall is reached, declare all invisible tiles
     as dangerous"""
     if len(self.wall.living) <= 5:
         allTiles = [
             x for x in defaultdict.keys(elements.occurrence)
             if not x.isBonus
         ]
         for tile in allTiles:
             assert isinstance(tile, Tile), tile
         # see https://www.logilab.org/ticket/23986
         invisibleTiles = set(x for x in allTiles
                              if x not in self.visibleTiles)
         msg = i18n('Short living wall: Tile is invisible, hence dangerous')
         self.dangerousTiles = list(x for x in self.dangerousTiles
                                    if x[1] != msg)
         self.dangerousTiles.append((invisibleTiles, msg))
예제 #5
0
파일: player.py 프로젝트: KDE/kajongg
 def findDangerousTiles(self):
     """update the list of dangerous tile"""
     pName = self.localName
     dangerous = list()
     expMeldCount = len(self._exposedMelds)
     if expMeldCount >= 3:
         if all(x in elements.greenHandTiles for x in self.visibleTiles):
             dangerous.append((elements.greenHandTiles,
                               m18n('Player %1 has 3 or 4 exposed melds, all are green', pName)))
         group = list(defaultdict.keys(self.visibleTiles))[0].group
         # see http://www.logilab.org/ticket/23986
         assert group.islower(), self.visibleTiles
         if group in Tile.colors:
             if all(x.group == group for x in self.visibleTiles):
                 suitTiles = set([Tile(group, x) for x in Tile.numbers])
                 if self.visibleTiles.count(suitTiles) >= 9:
                     dangerous.append(
                         (suitTiles, m18n('Player %1 may try a True Color Game', pName)))
             elif all(x.value in Tile.terminals for x in self.visibleTiles):
                 dangerous.append((elements.terminals,
                                   m18n('Player %1 may try an All Terminals Game', pName)))
     if expMeldCount >= 2:
         windMelds = sum(self.visibleTiles[x] >= 3 for x in elements.winds)
         dragonMelds = sum(
             self.visibleTiles[x] >= 3 for x in elements.dragons)
         windsDangerous = dragonsDangerous = False
         if windMelds + dragonMelds == expMeldCount and expMeldCount >= 3:
             windsDangerous = dragonsDangerous = True
         windsDangerous = windsDangerous or windMelds >= 3
         dragonsDangerous = dragonsDangerous or dragonMelds >= 2
         if windsDangerous:
             dangerous.append(
                 (set(x for x in elements.winds if x not in self.visibleTiles),
                  m18n('Player %1 exposed many winds', pName)))
         if dragonsDangerous:
             dangerous.append(
                 (set(x for x in elements.dragons if x not in self.visibleTiles),
                  m18n('Player %1 exposed many dragons', pName)))
     self.dangerousTiles = dangerous
     if dangerous and Debug.dangerousGame:
         self.game.debug('dangerous:%s' % dangerous)
예제 #6
0
 def findDangerousTiles(self):
     """update the list of dangerous tile"""
     pName = self.localName
     dangerous = list()
     expMeldCount = len(self._exposedMelds)
     if expMeldCount >= 3:
         if all(x in elements.greenHandTiles for x in self.visibleTiles):
             dangerous.append((elements.greenHandTiles,
                  m18n('Player %1 has 3 or 4 exposed melds, all are green', pName)))
         color = defaultdict.keys(self.visibleTiles)[0][0]
         # see http://www.logilab.org/ticket/23986
         assert color.islower(), self.visibleTiles
         if color in 'sbc':
             if all(x[0] == color for x in self.visibleTiles):
                 suitTiles = set([color+x for x in '123456789'])
                 if self.visibleTiles.count(suitTiles) >= 9:
                     dangerous.append((suitTiles, m18n('Player %1 may try a True Color Game', pName)))
             elif all(x[1] in '19' for x in self.visibleTiles):
                 dangerous.append((elements.terminals,
                     m18n('Player %1 may try an All Terminals Game', pName)))
     if expMeldCount >= 2:
         windMelds = sum(self.visibleTiles[x] >=3 for x in elements.winds)
         dragonMelds = sum(self.visibleTiles[x] >=3 for x in elements.dragons)
         windsDangerous = dragonsDangerous = False
         if windMelds + dragonMelds == expMeldCount and expMeldCount >= 3:
             windsDangerous = dragonsDangerous = True
         windsDangerous = windsDangerous or windMelds >= 3
         dragonsDangerous = dragonsDangerous or dragonMelds >= 2
         if windsDangerous:
             dangerous.append((set(x for x in elements.winds if x not in self.visibleTiles),
                  m18n('Player %1 exposed many winds', pName)))
         if dragonsDangerous:
             dangerous.append((set(x for x in elements.dragons if x not in self.visibleTiles),
                  m18n('Player %1 exposed many dragons', pName)))
     self.dangerousTiles = dangerous
     if dangerous and Debug.dangerousGame:
         self.game.debug('dangerous:%s' % dangerous)
예제 #7
0
파일: util.py 프로젝트: MShaffar19/ctk
 def keys(self):
     return [
         k for k in defaultdict.keys(self)
         if k[0] != '_' and k != 'trait_names'
     ]
예제 #8
0
파일: util.py 프로젝트: kidaa/pyparallel
 def keys(self):
     return [
         k for k in defaultdict.keys(self)
             if k[0] != '_' and k != 'trait_names'
     ]