Wordle
Analysis of a daily word game "Wordle"
https://www.powerlanguage.co.uk/wordle/
Description
Worlde is a daily word game in which a player attempts to guess a 5-letter word in at most 6 trials. After each guess for each letter he recieves a response whether or not it is present in a word and if so, is it in correct position. Thus, for each letter we have three options:
- The letter is correct and in a correct position, denoted by a green colour and letter C in this project
- The letter is correct (i.e. it exists in a word) but in an incorrect position, denoted by a yellow colour and letter I in this project
- The letter is incorrect (i.e. is not present in a word), denoted by a gray colour and letter O in this project
The game has two variants: easy and hard. An easy variant allows to guess any word at each stage of the game. The hard version forces the player to guess the word that conforms to the information that has already been discovered (e.g. he is not allowed to guess the words which contain letters that were previously revealed to not be present in a word). In this project we focus on the hard variant.
Instalation
The project requires several packages - the information is contained in the requirements.txt
file and can easily be installed with:
using pip
pip install -r requirements.txt
using Conda
conda create --name <env_name> --file requirements.txt
Aim
The aim of the project is to find the strategy that guesses the word in as little number of guesses as possible.
Files
wordle.py
Main package of the project - contains all the code needed to generate game tree and compute the best possible strategy. It implements two classes:
-
GameState: tracks the state of the game - which letters have been eliminated, which are in their correct positions and which exist in a word but at a different position
-
Node: tree data structure for keeping track of all possible scenarios of the game
words.py
Scrapes the list of 5-letter english words from the website:
game.py
Simulates the Wordle game by sampling a random word from the list and then repeatedly querying the player for a 5-letter guess and replying with a 5-letter response code (consisting of the letters C, I and O as described in the Description section).
Example usage:
Guess TARES and type the response: OIOOO
Guess PLAIN and type the response: OOCIO
Guess KHAZI and type the response: OOCOC
Guess ABACI and type the response: IOCOC
Guess UMAMI and type the response: CCCCC
It took 5 guesses.
solve.py
Solves the Wordle game by repeatedly providing the player with a guess and then asking him for a 5-letter response code (consisting of the letters C, I and O as described in the Description section) until there word has been guessed correctly. It needs to be provided with solver.json
file which is produced by the attached Jupyter Notebook.
Example usage
Enter your guess: TARES
The response was: OIOOO
Enter your guess: PLAIN
The response was: OOCIO
Enter your guess: KHAZI
The response was: OOCOC
Enter your guess: ABACI
The response was: IOCOC
Enter your guess: UMAMI
Correct! It took you 5 guesses.
wordle.ipynb
The Jupyter Notebook with the analysis of the game which also computes the solver.json
file for the optimal strategy needed for the solve.py
script.
License
Project is distributed under the MIT license