A cheating version of Hangman in Java. Instead of picking a word up front, the game keeps every word still possible and stalls the player by always choosing the largest surviving set.
Regular Hangman commits to a secret word at the start. Evil Hangman never does. It holds the whole set of candidate words and, on each guess, partitions them by letter pattern and keeps the biggest group. To the player it looks like a normal game, but the "word" is only pinned down when no dodge is left. It is a small, clean example of using data structures to defer a decision as long as possible.
- Partitioning a word list into letter-pattern families each turn
- Choosing the largest family to maximize remaining ambiguity
- Working set of candidate words held in a
Set, grouped with aMap<String, Set<String>> - Tracking guessed letters with a
SortedSetand building the revealed word withStringBuilder - Custom exceptions (
EmptyDictionaryException,GuessAlreadyMadeException) - Interface-driven design (
IEvilHangmanGame) with a passoff test suite - File-based dictionary loading and word-length filtering
EvilHangmanGame: the game engine (dictionary load, per-guess partitioning, largest-subset selection, win/loss tracking)EvilHangman: the command-line driverIEvilHangmanGame, custom exceptions, andHangmanTestpassoff tests- Bundled dictionaries (
dictionary.txtand smaller word lists)
- Java
- Java Collections (
Set,Map,SortedSet) - JUnit passoff tests
Compile and run against a dictionary and a word length:
javac -d out src/hangman/*.java
java -cp out hangman.EvilHangman dictionary.txt <wordLength> <guesses>Guess letters at the prompt. The game reveals as little as it can each turn and only loses to you when it genuinely runs out of words to hide behind.