This makes the code a little uglier, but cuts time and memory in half when
building a new Worddle board. Also updated the boards to not save a reference
to the wordtrie, so after generating the board, it's free for garbage
collection.
Previously every word would be LCYAN+word+LGRAY (or GRAY+word+LGRAY) and all
these extra color codes would cause the message to be truncated when a lot of
words are found. Compacted by only sending a color code when a color change
is needed.
Generate 5 boards and pick the one with the most solutions. It's more fun
when there are more solutions to be found.
Refactored a little - the board is now a class WorddleBoard. Moved the
generation and solution discovery to WorddleBoard. This simplifies Worddle a
little bit, but it probably could be simplified further.
Trying to make the game a little quieter in the main channel, and in general
cut down on flooding. Still no verbosity tuning, but this should be a more
reasonable default level.
Worddle has a lot of logic dedicated to formatting text, and it makes the
code a little unreadable. I tried to move most of the format strings out
as constants (and color them once instead of every time). The resulting
code is a little cleaner looking, but I'm not sure I love it.
It was using the string 'worddle' as the unique identifier in all
scheduled events, which meant that a second game (in another channel,
at the same time) will erase the first game's scheduled events.
Now use the Worddle object's unique identifier when scheduling events.
Worked around a supybot bug and abstracted shutdown to calling
game.stop(now=True). This way the Wordgames class can be ignorant
of the details of stopping a game.
* Whenever someone joins, put at least 5 seconds on the pre-game clock.
(If more than 5 seconds are already remaining, do nothing.)
* Use the entire delay period before showing "Get ready!".
* Delay 3 more seconds before jumping into the game.
Added support for broadcasting messages in one shot if the IRC server
supports multiple targets. (Inspircd only right now, need to add support for
more servers.) This will hopefully reduce flood issues and latency.
Cleaned up messages, improved use of color, added join notifications,
added a 'get ready' state 5 seconds before game starts.
Some code cleanup and refactoring.
This is a clone of a famous game involving a 4x4 grid of random letters.
It uses Plugin's inFilter to filter out private messages to the bot during
the game, so that they are not treated as commands. You can still send
commands to the bot using the command character during this period. When
the game ends, the filter puts things back to normal.
Also implemented a new command when DEBUG is True, wordsolve, which shows
the solution to the current wordgame.
It shouldn't need to know what specific parameters the game will take.
(And its "length" parameter was out of date since the games currently
use "difficulty".)
Some solution length logic was previously moved to handle_message. Some of
the code in _valid_solution became nonsensical (not broken, just weird).
Cleaned up.
Now defaults to the /usr/share/dict/american-english dictionary which is
probably found on many Linux systems today (avoiding the need to dig up a word
file on the interwebs). On Debian/Ubuntu, you can 'apt-get install wamerican'.
Added a configurable regexp to filter the word list down to reasonable words.
Defaults to allow lowercase a-z only, therefore filtering out proper names,
hyphenations, contractions, and words with accented characters like "adiós".
(But hopefully still supporting non-English users by allowing this to be
changed.)
Instead of taking lengths, the games now take easy|medium|hard|evil.
These values correspond to a range of puzzle lengths, word lengths, and
number of possible solutions. I attempted to tune them to reasonable
values, but I could see them changing.
Also did a little more code clean-up.
No substrings should occur in any word of any solution (not just two
successive words). This is really going to narrow down the set of puzzles,
hopefully it doesn't churn or get repetitive.
The two games have a lot in common, so factored out a base class called
WordChain that implements most of the logic. The game-specific behaviors
are implemented in the (now smaller) WordTwist and WordShrink classes.
Optimized to build a map of word relationships first and then derive all game
behavior from that map. This could probably be improved even more, but for
the moment it is working nicely.