コード例 #1
0
 def _addRandomWord(self):
     if 'randomPlayers' not in self._roundSettings or not self._roundSettings[
             'randomPlayers']:
         return
     if 'randomWordsLimit' not in self._roundSettings or not self._roundSettings[
             'randomWordsLimit']:
         return
     randomPlayersProcessed = 0
     for randomPlayer in self._RANDOM_PLAYER:
         if randomPlayersProcessed >= self._roundSettings['randomPlayers']:
             break
         if not Player.get(telegram_id=randomPlayer['id']):
             Player.add(telegram_id=randomPlayer['id'],
                        name=randomPlayer['first_name'])
         randomPlayersProcessed += 1
         if Word.getListByRoundId(telegram_id=randomPlayer['id'],
                                  **self._gameState['query']):
             continue
         randomWordsCount = 0
         wordsAdded = 0
         while wordsAdded <= self._roundSettings['randomWordsLimit']:
             if randomWordsCount > 20:
                 break
             randomWordsCount += 1
             word = self._getRandom(
                 "ushakov",
                 wordMinLength=self._roundSettings['minWordsPerPlayer'])
             if not word:
                 continue
             Word.add(word=word,
                      player_id=Player.getId(randomPlayer),
                      wordsLimit=self._roundSettings['randomWordsLimit'],
                      wordMinLength=self._roundSettings['minWordLength'],
                      **self._gameState['query'])
             wordsAdded += 1
コード例 #2
0
ファイル: round.py プロジェクト: sabnak/WordsJugglerBot
 def getWordsListByAuthor(round_id):
     plainWorldsList = Word.getListByRoundId(round_id, fullAccess=True)
     parsedWordsList = {}
     for row in plainWorldsList:
         if row['telegram_id'] not in parsedWordsList:
             parsedWordsList[row['telegram_id']] = [row['name'], []]
         parsedWordsList[row['telegram_id']][1].append(row['word'])
     return parsedWordsList
コード例 #3
0
ファイル: perfectWord.py プロジェクト: sabnak/WordsJugglerBot
 def setPlayerState(self, update):
     self._refreshGameState(checkGameStatus=True)
     if self._gameState['roundStatus'] != Round.STATUS_PREPARATION:
         return "Поздняк метаться. Раунд уже запущен. Молись!"
     player_id = Player.getId(update.message.chat)
     playerWords = Word.getListByRoundId(player_id=player_id,
                                         **self._gameState['query'])
     if len(playerWords) < self._roundSettings['minWordsPerPlayer']:
         return "Надо предложить побольше словцов, чтобы быть готовым. Осталось предложить: %d/%d" % (
             len(playerWords), self._roundSettings['minWordsPerPlayer'])
     return "Ты больше не готов к игре в этом раунде, трусиха" if not Player.setState(player_id=player_id, round_id=self._gameState['round_id']) else \
      "Ты изготовился к игре. Удач!"
コード例 #4
0
ファイル: perfectWord.py プロジェクト: sabnak/WordsJugglerBot
    def getPlayerWordsByRound(self, round_id=None, fullAccess=False):
        """
		:param round_id: int
		:param fullAccess: bool if True access to to all words otherwise your own
		:return: list of founded words
		"""
        self._refreshGameState()

        o = dict(game_id=self._gameState['query']['game_id'],
                 player_id=self._playerState['id'],
                 fullAccess=fullAccess,
                 round_id=round_id
                 if round_id else self._gameState['query']['round_id'])

        return Word.getListByRoundId(**o)
コード例 #5
0
ファイル: perfectWord.py プロジェクト: sabnak/WordsJugglerBot
    def getCandidates(self, update):
        self._refreshGameState(checkGameStatus=True)

        self._addRandomWord()
        fullInfoWordsList = Word.getListByRoundId(fullAccess=True,
                                                  **self._gameState['query'])

        wordsByPlayer = dict()
        randomPlayersList = []

        for wordInfo in fullInfoWordsList:

            if wordInfo['telegram_id'] in self._RANDOM_PLAYER_IDS and wordInfo[
                    'telegram_id'] not in randomPlayersList:
                randomPlayersList.append(wordInfo['telegram_id'])
            if wordInfo['player_id'] not in wordsByPlayer:
                wordsByPlayer[wordInfo['player_id']] = dict(
                    words=[],
                    isReady=Player.getState(
                        player_id=wordInfo['player_id'],
                        round_id=self._gameState['round_id']),
                    name=wordInfo['name'],
                    telegram_id=wordInfo['telegram_id'],
                    player_id=wordInfo['player_id'],
                )
            wordsByPlayer[wordInfo['player_id']]['words'].append(
                (wordInfo['id'], wordInfo['word'], wordInfo['player_id']))

        unreadyPlayers = [
            p['name'] for p in wordsByPlayer.values() if not p['isReady']
            and p['telegram_id'] not in self._RANDOM_PLAYER_IDS
        ]

        if len(wordsByPlayer
               ) < self._roundSettings['minPlayers'] + len(randomPlayersList):
            return "Что-то маловато народца набралось для игры (%d/%d). Зови друзей" % (
                len(wordsByPlayer) - len(randomPlayersList),
                self._roundSettings['minPlayers'])
        if len(wordsByPlayer
               ) > self._roundSettings['maxPlayers'] - len(randomPlayersList):
            return "Ого сколько вас набежало. Слишком много вас, а я один (%d/%d). Пошли вон!" % (
                len(wordsByPlayer) + len(randomPlayersList),
                self._roundSettings['maxPlayers'])
        if unreadyPlayers:
            return "Слишком много тормозов в игре. Я не могу показать тебе словцы, пока все не будут готовы. Список тормозов:\n%s" % " ".join(
                unreadyPlayers)
        if self._gameState['roundStatus'] == Round.STATUS_PREPARATION:
            Round.updateRoundStatus(round_id=self._gameState['round_id'],
                                    status=Round.STATUS_IN_PROGRESS)

        wordsList = self._splitWordsIntoGroups([
            word for wordsInfo in wordsByPlayer.values()
            for word in wordsInfo['words']
        ])

        return """
			Вот список всех словцов. Кроме того я добавил в него несколько случайных (а может и нет). Хехе.
			Добавь вместо ноликов свои баллы.
			<b>%s</b>
			Суммарное максимальное количество баллов: %d
			Суммарное минимальное количество баллов: %d
			Максимальное количество баллов на слово: %d
		""" % ("\n".join([
            "Группа %d: %s" % (i, " 0 ".join(w)) for i, w in wordsList.items()
        ]) + " 0", self._roundSettings['maxWeightPerRound'],
         self._roundSettings['minWeightPerRound'],
         self._roundSettings['maxWeightPerWord'])