About
This is a Python implementation of wordle designed to make it easy to run multiple games and evaluate different strategies. For examples of how to use the package, see the test files.
Strategies
For this package a strategy is defined as a function which takes in a Game
object and returns that object as a solved game. A simple strategy might look like this:
def cheat(game): game.guess(game.target_word) return game
While it’s not particularly interesting to use the target_word
attribute of the game object, there are attributes which you would actually use in game like the greens
, yellows
, and greys
built in arrays. There are also a handful of helpful functions in the strategies.py file. Here’s an example of a slightly more sophisticated strategy.
from wordle_strategy_evaluation.game import DEFAULT_WORDS_LIST import wordle_strategy_evaluation.strategy as st def guess_by_freq(game): while not game.game_over: filtered = st.filter_all(game) rate_words = st.score_words_list(filtered, st.DEFAULT_FREQS) best_word = list(rate_words.keys())[0] game.guess(best_word) return game
The st.filter_all
function looks at the greens, yellows, and greys from previous guesses and filters the complete word list accordingly. The st.score_words
just scores words according to how often a letter appears in a given position. This strategy will solve a wordle in about 3.81 guesses on average.