Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EvilHangman

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.

What this demonstrates

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.

Concepts demonstrated

  • 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 a Map<String, Set<String>>
  • Tracking guessed letters with a SortedSet and building the revealed word with StringBuilder
  • Custom exceptions (EmptyDictionaryException, GuessAlreadyMadeException)
  • Interface-driven design (IEvilHangmanGame) with a passoff test suite
  • File-based dictionary loading and word-length filtering

What's implemented

  • EvilHangmanGame: the game engine (dictionary load, per-guess partitioning, largest-subset selection, win/loss tracking)
  • EvilHangman: the command-line driver
  • IEvilHangmanGame, custom exceptions, and HangmanTest passoff tests
  • Bundled dictionaries (dictionary.txt and smaller word lists)

Stack

  • Java
  • Java Collections (Set, Map, SortedSet)
  • JUnit passoff tests

Usage

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.

About

Cheating Hangman in Java that keeps every possible word alive and always picks the largest surviving set to stall the player

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages