diff --git a/README.md b/README.md index 7b296bc..c3005ed 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,15 @@ To be a valid guess, words must: * appear in the dictionary file. At the end of the game, if a word was found by multiple players, it is not -counted. The remaining words contribute to your score, at 1 point per letter. +counted. The remaining words contribute to your score using these values: + + Length | Value + --------+------- + 3, 4 | 1 point + 5 | 2 points + 6 | 3 points + 7 | 5 points + 8+ | 11 points ### WordShrink diff --git a/plugin.py b/plugin.py index 1d431b6..41c0f6a 100644 --- a/plugin.py +++ b/plugin.py @@ -38,7 +38,7 @@ import supybot.world as world from trie import Trie -DEBUG = False +DEBUG = True WHITE = '\x0300' GREEN = '\x0303' @@ -60,6 +60,10 @@ def info(message): def error(message): log.error('Wordgames: ' + message) +def point_str(value): + "Return 'point' or 'points' depending on value." + return 'point' if value == 1 else 'points' + # Ideally Supybot would do this for me. It seems that all IRC servers have # their own way of reporting this information... def get_max_targets(irc): @@ -322,6 +326,16 @@ class Worddle(BaseGame): 1: 'BJKQVXZ', } + POINT_VALUES = { + 3: 1, + 4: 1, + 5: 2, + 6: 3, + 7: 5, + } + + MAX_POINTS = 11 # 8 letters or longer + class State: PREGAME = 0 READY = 1 @@ -340,7 +354,10 @@ class Worddle(BaseGame): return cmp(self.get_score(), other.get_score()) def get_score(self): - return sum(map(len, self.unique)) + score = 0 + for word in self.unique: + score += Worddle.POINT_VALUES.get(len(word), Worddle.MAX_POINTS) + return score def render(self): words = sorted(list(self.unique) + list(self.dup)) @@ -353,9 +370,10 @@ class Worddle(BaseGame): words_text += '%s%s%s ' % (color, word, LGRAY) if not words_text: words_text = '%s-none-%s' % (GRAY, LGRAY) - return '%s%s%s gets %s%d%s points (%s)' % \ - (WHITE, self.player, LGRAY, LGREEN, self.get_score(), - LGRAY, words_text.strip()) + score = self.get_score() + return '%s%s%s gets %s%d%s %s (%s)' % \ + (WHITE, self.player, LGRAY, LGREEN, score, + LGRAY, point_str(score), words_text.strip()) class Results: "Represents results for all players." @@ -581,10 +599,11 @@ class Worddle(BaseGame): # Notify players for result in results.player_results.values(): + score = result.get_score() self.announce_to(result.player, - ("%sTime's up!%s You scored %s%d%s points! Check " + ("%sTime's up!%s You scored %s%d%s %s! Check " "%s%s%s for complete results.") % - (WHITE, LGRAY, LGREEN, result.get_score(), LGRAY, WHITE, + (WHITE, LGRAY, LGREEN, score, LGRAY, point_str(score), WHITE, self.channel, LGRAY), now=True) # Announce game results in channel @@ -600,7 +619,8 @@ class Worddle(BaseGame): message += ' tied ' else: message += ' wins ' - message += 'with %s%d%s points!' %(WHITE, winners[0].get_score(), LGRAY) + message += 'with %s%d%s %s!' % (WHITE, winners[0].get_score(), LGRAY, + point_str(winners[0].get_score())) self.announce(message) def _display_board(self, nick=None):