Exemple #1
0
 def colorize(word):
     if word in valid:
         return format.format(word, bold = True, fg = 3)
     elif word in alreadyfound:
         return format.format(word, bold = False, fg = 6)
     else:
         return format.format(word, bold = False, fg = 4)
Exemple #2
0
 def on_switch_in(self):
     self.submittals = {}
     self.n = 0
     self.prompt = self.prompt_source.generate(self)
     self.broadcast('%s%s' % (
             format.format('Prompt: ', **self.color_prompt_prefix),
             format.format(self.prompt, **self.color_prompt)))
     self.schedule(self.submit_times, WittyVote)
     self.broadcast('You have %i seconds to submit.' % self.remaining())
Exemple #3
0
    def on_switch_out(self):
        votes = self.votes.items()
        self.tally = []
        padding = max(len(user) for (_, user) in self.entries) + 1
        _v = [[user2 for user2, vote in votes if vote == i] for ((i, entry), user) in self.entries]
        padding_v = max(len(str(len(v))) for v in _v) + 2
        self.broadcast('%s%s' % (
                format.format('Prompt: ', **self.color_prompt_prefix),
                format.format(self.prompt, **self.color_prompt)))
        for ((i, entry), user), v in zip(self.entries, _v):
            nv = len(v)
            if nv == 0: p = ''
            elif user not in self.votes: p = ''
            else: p = '+%i' % nv
#             if nv == 0:
#                 msg = 'No votes.'
#             else:
#                 if nv == 1:
#                     msg = '1 vote '
#                 else:
#                     msg = '%i votes ' % nv
#                 msg += '(%s)' % (', '.join(v))
            if nv == 0:
                msg = 'No votes.'
            else:
                msg = 'Votes: %s' % (', '.join(map(str, v)))
            self.broadcast('%(leftbrack)s%(num)s%(rightbrack)s%(user)s%(points)s%(entry)s%(votes)s' % dict(
                leftbrack = format.format('[', **self.color),
                num = format.format(str(i), **self.color_entrynum),
                rightbrack = format.format('] ', **self.color),
                user = format.format(str(user).ljust(padding), **self.color),
                points = format.format(p.ljust(padding_v), **self.color),
                entry = format.format(entry, **self.color_entry_vote),
                votes = format.format(' | ' + msg, **self.color)
                ))
            if user not in self.votes:
                self.broadcast('$B%s$B did not vote... no point for him or her!' % user)
            else:
                if nv:
                    self.tally.append([nv, user])
                    self.points[user] += nv
        self.tally.sort(key = lambda (x, y): (-x, y))
        if len(self.tally) >= 2 and self.tally[0][0] > self.tally[1][0]:
            user = self.tally[0][1]
            bonus = self.tally[0][0] - self.tally[1][0]
            bonus = min(bonus, self.max_bonus)
            self.tally[0][0] += bonus
            self.broadcast('$B%s$B gets a bonus of %i points for first place!' % (user, bonus))
            self.points[user] += bonus
        pts = [(y, x) for (x, y) in self.points.items()]
        pts.sort(key = lambda (x, y): (-x, y))
        if pts:
            self.broadcast('Score: ' + ', '.join('%s: %i' % (user, p) for (p, user) in pts))
        self.pts = pts
Exemple #4
0
    def submit(self, info, *message):
#         """
#         Usage: $Bsubmit <entry>$B

#         Submit an entry which completes the prompt.
#         """
        
        if not message:
            raise util.UsageError('You must submit something!')
        message = ' '.join(map(str, message))
        if info.user in self.submittals:
            self.submittals[info.user][1] = message
            info.reply('You have revised your entry: %s' % message)
        else:
            self.n += 1
            self.players.add(info.user)
            self.submittals[info.user] = [self.n, message]
            self.broadcast('%s%s%s' % (
                    format.format('[', **self.color),
                    format.format(str(self.n), **self.color_entrynum),
                    format.format('] was submitted!', **self.color)))
Exemple #5
0
 def on_switch_in(self):
     self.entries = [(y, x) for (x, y) in self.submittals.items()]
     if len(self.entries) < self.min_entries:
         self.strikes += 1
         self.broadcast('Time out! Unfortunately, we need at least %i entries to play.' % self.min_entries)
         self.switch(WittyWait, switch_out = False)
         return
     self.strikes = 0
     self.entries.sort()
     self.votes = {}
     self.broadcast('Time out! Here are the entries:')
     self.broadcast('%s%s' % (
             format.format('Prompt: ', **self.color_prompt_prefix),
             format.format(self.prompt, **self.color_prompt)))
     for (i, entry), user in self.entries:
         self.broadcast('%(leftbrack)s%(num)s%(rightbrack)s%(entry)s' % dict(
                 leftbrack = format.format('[', **self.color),
                 num = format.format(str(i), **self.color_entrynum),
                 rightbrack = format.format('] ', **self.color),
                 entry = format.format(entry, **self.color_entry)
                 ))
                 
     total = self.min_vote_time + self.seconds_per_entry_vote * len(self.entries)
     self.schedule([total - total/2, total/2], WittyWait)
     self.broadcast('You have %i seconds to vote.' % self.remaining())
Exemple #6
0
    def command_check(self, info, word):
        """
        Usage: $Bcheck <word>$B
        
        Check if the word is in the dictionary, that it is on the grid
        and that it is long enough. You can use this during the game
        if you want to know why one of your words was rejected.
        """
        word = word.lower()
        
        if word not in self.wordlist:
            info.reply('%s is not in the %s wordlist.' % (format.format(word, fg = 4), self.language))

        elif not self.is_on_grid(word):
            info.reply('%s is a word, but it cannot be formed on the grid.' % format.format(word, fg = 4))

        elif len(word) < self.min_word_length:
            info.reply('%s is a word and can be found on the grid, but it is not long enough (it needs to be at least $B%s$B letters long).'
                       % (format.format(word, fg = 4), self.min_word_length))

        else:
            pts = len(word) - self.min_word_length + 1
            info.reply('%s is valid and worth $B%s$B point%s.' % (format.format(word, bold = True, fg = 3), pts, 's' if pts > 1 else ''))
Exemple #7
0
 def colorize(word): 
     if word in dups:
         return format.format(word, bold = False)
     else:
         return format.format(word, bold = True)