A Java program that plays Wordle by minimax. You tell it the feedback Wordle gave, it tells you what to guess next. CS101 term project at Özyeğin University.
The dictionary is about 14,000 five-letter words, loaded from words.txt on the
classpath. The opening guess is hardcoded to salet, which splits the space
well on the first move.
Every guess after that is chosen by minimax. For each candidate word the solver
works out how the remaining words would bucket by feedback pattern, then picks
the word whose largest bucket is smallest (generateNextGuessIndex calling
maximumFeedbackSetCountForWord). That is the guess with the best guaranteed
worst case, whatever the answer turns out to be.
Once you enter the feedback, WordList.reduce throws out every word inconsistent
with it and the loop repeats. If the answer is not in the dictionary the solver
runs out of candidates and says so rather than hanging.
Two extras: each guess is looked up on the free
DictionaryAPI through HttpClient and Gson, so you
see what the word means, and the program shows the probability that the current
guess is the answer.
The project got 11 out of 10. The extra point was for handling duplicate letters
correctly, which the instructor called the sauna issue after the word sauna and
its two as.
The trap is that feedback on a repeated letter is not independent. A green on one occurrence must not license a yellow on the other, and how many of a letter the answer actually contains bounds how many yellows you can hand out. Naive comparison gets this wrong, and it is a quiet bug: it only surfaces on words with repeats, so it passes most of the words you would test with.
The stated requirements were only that the program give up when it cannot find the word, and close itself on all-green feedback.
JDK 17 or newer, for the switch expressions and java.net.http.HttpClient, plus
Gson on the classpath. Internet access is only needed for the definition lookups.
Open the project, mark src as sources root, add Gson to the dependencies, and
run main in Main.java. The
interface is Swing JOptionPane dialogs.
Feedback goes in as five characters: g green, y yellow, b black. So gybbg
means the first and last letters are placed correctly, the second letter is in the
word but somewhere else, and the middle two are not in it at all.
src/tr/edu/ozyegin/cs101/wordlesolver/
├── Main.java # entry point, game loop, Swing dialogs
├── WordList.java # dictionary, minimax selection, reduction
├── Word.java # a word and its feedback generation
├── Feedback.java # parses and represents g/y/b
├── FeedbackGenerator.java # feedback between a guess and an answer
├── Analysis.java # guess analysis helpers
├── DictionaryLookup.java # DictionaryAPI client
├── Wordle.java # game model
├── WordleSolver.java # shared constants
└── words.txt # dictionary
Written with Arhan (@vinnipukh).
MIT, see LICENSE.

