Course:CPSC312-2023/Wordle Solver

From UBC Wiki

What is the problem?

We would like to create a solver for the popular word-guessing game Wordle using Prolog. The game works by having six tries to guess a five-letter word, and by indicating how close we are to guessing the answer through marking when letters are in the correct position and when letters are contained in the word but not in the correct position.

What is the something extra?

We made use of WordNet as our collection of words from which to search for the Wordle answer. Because Wordle always uses a 5 letter word, we created a predicate that asserts that a word is contained in WordNet's collection of words and is of length five.

What did we learn from doing this?

We learned that prolog is very well suited to this kind of task. The core functionality worked out to be three simple predicates: green asserting that a given word contains a certain letter in a certain position, yellow asserting that a given word contains a certain letter somewhere other than a given position, and notcontain asserting that a given word does not contain the given letter. The more difficult part of this problem was coming up with a predicate to simplify the input for the user. Instead of having the user input a long list of facts using the green, yellow, and notcontain predicates, we wanted to have the user input all of the information they know about the word in a more condensed manner. Figuring out how best to simplify it proved to be a challenge, but in the end we settled on having the user add in the letters previously guessed by them, as well as the indices of the corresponding letters to the console. We also simplified choosing whether the letter appeared green, yellow or grey (the word does not contain the letter) using a menu where they could choose a number corresponding to the type of the guessed letter. This input was then given to the solve predicate which handled all the types of letters and their indices to generate a valid guess that matched all the given information.

Links to code etc

https://github.com/misophie/wordle-solver