mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-05-06 11:33:42 -05:00
Customize Worddle min word length.
Instead of a hard-coded 3, you can set a configuration value or pass a --min=N parameter to the start command.
This commit is contained in:
parent
6648d546e4
commit
eb8ca3fb60
17
README.md
17
README.md
@ -21,10 +21,13 @@ The following commands are exposed by this plugin:
|
|||||||
|
|
||||||
`worddle [start|join|stop|stats]`
|
`worddle [start|join|stop|stats]`
|
||||||
|
|
||||||
> Start a new Worddle game, join an existing game, or stop the current game.
|
> Play a Worddle game. Use the following subcommands:
|
||||||
> `start` is the default if nothing is specified. `stop` is an alias for
|
>
|
||||||
> @wordquit, added for ease of use. Use 'stats' to see a few bits of
|
> start (Default) Start a new Worddle game, optional arguments:
|
||||||
> information about the board after the game.
|
> --min=N minimum acceptable word length (overrides config)
|
||||||
|
> join Join a running game
|
||||||
|
> stop Stop a currently running game (alias for @wordquit)
|
||||||
|
> stats Display some post-game statistics about the board
|
||||||
|
|
||||||
`wordshrink [difficulty]`
|
`wordshrink [difficulty]`
|
||||||
|
|
||||||
@ -146,6 +149,12 @@ Configuration Variables
|
|||||||
>
|
>
|
||||||
> Default: `90`
|
> Default: `90`
|
||||||
|
|
||||||
|
`plugins.Wordgames.worddleMinLength`
|
||||||
|
|
||||||
|
> The minimum length of a word that will be accepted in Worddle.
|
||||||
|
>
|
||||||
|
> Default: `3`
|
||||||
|
|
||||||
A Technical Note About Worddle
|
A Technical Note About Worddle
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
|
@ -54,4 +54,9 @@ conf.registerGlobalValue(Wordgames, 'worddleDuration',
|
|||||||
registry.NonNegativeInteger(90,
|
registry.NonNegativeInteger(90,
|
||||||
'Duration (in seconds) of a Worddle game ' +
|
'Duration (in seconds) of a Worddle game ' +
|
||||||
'(not including the initial delay).'))
|
'(not including the initial delay).'))
|
||||||
|
|
||||||
|
conf.registerGlobalValue(Wordgames, 'worddleMinLength',
|
||||||
|
registry.PositiveInteger(3, 'Minimum length of an acceptable word in a ' +
|
||||||
|
'Worddle game.'))
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
37
plugin.py
37
plugin.py
@ -137,13 +137,12 @@ class Wordgames(callbacks.Plugin):
|
|||||||
irc.reply('No game is currently running.')
|
irc.reply('No game is currently running.')
|
||||||
wordsolve = wrap(wordsolve, ['channel'])
|
wordsolve = wrap(wordsolve, ['channel'])
|
||||||
|
|
||||||
def worddle(self, irc, msgs, args, channel, command):
|
def worddle(self, irc, msgs, args, channel, command, extra_args):
|
||||||
"""[command]
|
"""[command]
|
||||||
|
|
||||||
Play a Worddle game. Commands: [start|join|stop|stats] (default: start).
|
Play a Worddle game. Commands: [start|join|stop|stats] (default: start).
|
||||||
"""
|
"""
|
||||||
delay = self.registryValue('worddleDelay')
|
extra_args = extra_args.split()
|
||||||
duration = self.registryValue('worddleDuration')
|
|
||||||
if command == 'join':
|
if command == 'join':
|
||||||
game = self.games.get(channel)
|
game = self.games.get(channel)
|
||||||
if game and game.is_running():
|
if game and game.is_running():
|
||||||
@ -154,7 +153,11 @@ class Wordgames(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.reply('No game is currently running.')
|
irc.reply('No game is currently running.')
|
||||||
elif command == 'start':
|
elif command == 'start':
|
||||||
self._start_game(Worddle, irc, channel, msgs.nick, delay, duration)
|
delay = self.registryValue('worddleDelay')
|
||||||
|
duration = self.registryValue('worddleDuration')
|
||||||
|
min_length = self.registryValue('worddleMinLength')
|
||||||
|
self._start_game(Worddle, irc, channel, msgs.nick,
|
||||||
|
delay, duration, min_length, extra_args)
|
||||||
elif command == 'stop':
|
elif command == 'stop':
|
||||||
# Alias for @wordquit
|
# Alias for @wordquit
|
||||||
self._stop_game(irc, channel)
|
self._stop_game(irc, channel)
|
||||||
@ -169,7 +172,8 @@ class Wordgames(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.reply('Unrecognized command to worddle.')
|
irc.reply('Unrecognized command to worddle.')
|
||||||
worddle = wrap(worddle,
|
worddle = wrap(worddle,
|
||||||
['channel', optional('somethingWithoutSpaces', 'start')])
|
['channel', optional('somethingWithoutSpaces', 'start'),
|
||||||
|
optional('text', '')])
|
||||||
# Alias for misspelling of the game name
|
# Alias for misspelling of the game name
|
||||||
wordle = worddle
|
wordle = worddle
|
||||||
|
|
||||||
@ -433,16 +437,19 @@ class Worddle(BaseGame):
|
|||||||
def sorted_results(self):
|
def sorted_results(self):
|
||||||
return sorted(self.player_results.values(), reverse=True)
|
return sorted(self.player_results.values(), reverse=True)
|
||||||
|
|
||||||
def __init__(self, words, irc, channel, nick, delay, duration):
|
def __init__(self, words, irc, channel, nick, delay, duration, min_length,
|
||||||
|
extra_args):
|
||||||
# See tech note in the Wordgames class.
|
# See tech note in the Wordgames class.
|
||||||
self.parent = super(Worddle, self)
|
self.parent = super(Worddle, self)
|
||||||
self.parent.__init__(words, irc, channel)
|
self.parent.__init__(words, irc, channel)
|
||||||
self.board = self._generate_board()
|
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
self.min_length = min_length
|
||||||
|
self.max_targets = get_max_targets(irc)
|
||||||
|
self._handle_args(extra_args)
|
||||||
|
self.board = self._generate_board()
|
||||||
self.event_name = 'Worddle.%d' % id(self)
|
self.event_name = 'Worddle.%d' % id(self)
|
||||||
self.init_time = time.time()
|
self.init_time = time.time()
|
||||||
self.max_targets = get_max_targets(irc)
|
|
||||||
self.longest_len = len(max(self.board.solutions, key=len))
|
self.longest_len = len(max(self.board.solutions, key=len))
|
||||||
self.starter = nick
|
self.starter = nick
|
||||||
self.state = Worddle.State.PREGAME
|
self.state = Worddle.State.PREGAME
|
||||||
@ -566,6 +573,13 @@ class Worddle(BaseGame):
|
|||||||
formatted = Worddle.MESSAGES[name] % kwargs
|
formatted = Worddle.MESSAGES[name] % kwargs
|
||||||
self._broadcast_text(formatted, recipients, now)
|
self._broadcast_text(formatted, recipients, now)
|
||||||
|
|
||||||
|
def _handle_args(self, extra_args):
|
||||||
|
for arg in extra_args:
|
||||||
|
if arg.startswith('--min='):
|
||||||
|
self.min_length = int(arg[6:])
|
||||||
|
else:
|
||||||
|
raise WordgamesError('Unrecognized argument: %s' % arg)
|
||||||
|
|
||||||
def _get_ready(self):
|
def _get_ready(self):
|
||||||
self.state = Worddle.State.READY
|
self.state = Worddle.State.READY
|
||||||
self._broadcast('ready', now=True)
|
self._broadcast('ready', now=True)
|
||||||
@ -666,7 +680,7 @@ class Worddle(BaseGame):
|
|||||||
attempts = 5
|
attempts = 5
|
||||||
wordtrie = Trie()
|
wordtrie = Trie()
|
||||||
map(wordtrie.add, self.words)
|
map(wordtrie.add, self.words)
|
||||||
boards = [WorddleBoard(wordtrie, Worddle.BOARD_SIZE)
|
boards = [WorddleBoard(wordtrie, Worddle.BOARD_SIZE, self.min_length)
|
||||||
for i in range(0, attempts)]
|
for i in range(0, attempts)]
|
||||||
board_quality = lambda b: len(b.solutions)
|
board_quality = lambda b: len(b.solutions)
|
||||||
return max(boards, key=board_quality)
|
return max(boards, key=board_quality)
|
||||||
@ -674,9 +688,10 @@ class Worddle(BaseGame):
|
|||||||
class WorddleBoard(object):
|
class WorddleBoard(object):
|
||||||
"Represents the board in a Worddle game."
|
"Represents the board in a Worddle game."
|
||||||
|
|
||||||
def __init__(self, wordtrie, n):
|
def __init__(self, wordtrie, n, min_length):
|
||||||
"Generate a new n x n Worddle board."
|
"Generate a new n x n Worddle board."
|
||||||
self.size = n
|
self.size = n
|
||||||
|
self.min_length = min_length
|
||||||
self.rows = self._generate_rows()
|
self.rows = self._generate_rows()
|
||||||
self.solutions = self._find_solutions(wordtrie)
|
self.solutions = self._find_solutions(wordtrie)
|
||||||
|
|
||||||
@ -703,7 +718,7 @@ class WorddleBoard(object):
|
|||||||
if current[-1] == 'q': current += 'u'
|
if current[-1] == 'q': current += 'u'
|
||||||
node = wordtrie.find_prefix(current)
|
node = wordtrie.find_prefix(current)
|
||||||
if node:
|
if node:
|
||||||
if node['*'] and len(current) > 2:
|
if node['*'] and len(current) >= self.min_length:
|
||||||
result.add(current)
|
result.add(current)
|
||||||
# Explore all 8 directions out from here
|
# Explore all 8 directions out from here
|
||||||
offsets = [(-1, -1), (-1, 0), (-1, 1),
|
offsets = [(-1, -1), (-1, 0), (-1, 1),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user