copyright Steve J. Hodges   http://steveh.net/cs20j/cs20j-hw05.html

Fall 2018

Assignment 5 (Cinco!)

Directory Name

20j-5

Class Name

Cinco and Dictionary

Program Description

In this program, you will be creating a word guessing game called Cinco. In this game, the computer will pick a (random) secret five letter word from its Dictionary. A human player guesses a word. A word is only a legal guess if it appears in the Dictionary. A word is a legal secret word only if it appears in the Dictionary and does not have a repeated letter. A word list of about 2400 five letter words is provided (click this link to get the word list). The rest of the file consists of five-letter words, one per line, in alphabetical order.

Selecting a secret word randomly from a HashSet is tricky, so you if you prefer, you may add a second container (arrayList<String>) to hold only words that are legal secret words. (The HashSet will still hold all words.)

Each round, the player guesses a five-letter word. If the guess is correct, the computer reports how many guesses it took, notifies if the cheat code was used during the game, and the program ends. If the guess is incorrect, the computer says how many letters in the guess also exist in the secret word and how many of those letters are in the correct spot. The player then can make their next guess.

If the user enters the guess of 'xxxxx' (cheat code) the program should reveal the secret word. Using the cheat code should count as a guess and should not terminate the program. (Failure to correctly implement the cheat code will result in a major point deduction!) A sample run will be provided to illustrate how your program should work.

Any letter in your secret word should only be matched once. For example,
Secret: fable
Guess: eagle
results in 3,3 not 4,3.

This program should be constructed using two classes. One class, named Dictionary, will take care of inputting and storing the words from a file, selecting a random legal secret word from the list, and looking up words (guesses) to verify that they are in the dictionary. Your Dictionary class will use a HashSet<String> for quick lookup. The function that selects a random word from the dictionary must not select a word with a repeated letter. (A guess may have a repeated letter.) The other class, named Cinco, will take care of the game rules, keeping track of the game state, handling the user input and output, comparing the guess and secret words, and contain the main function. The main game loop (including i/o) must be in a function named play(). play() should be invoked from the main function in the Cinco class. Some starter code will be provided. Use of the provided code is optional. You may use it as is, modify it, or discard it.

This is a program with many details. I strongly urge you to keep your program compiling and running at all stages of your project. Keep all your functions simple at first—the minimum to compile and run. Add code to one function at a time and test as you code. Have Fun!

Your output must exactly match the style and formatting of the example, as the testing may be automated.

Sample Run

Cinco! Sample Solution
by Steve J. Hodges
I'm thinking of a five letter word...
Your Guess? xyxyz
I don't know that word.
Your Guess? hello
Matching: 2
In-Place: 0
Your Guess? stove
Matching: 3
In-Place: 1
Your Guess? venom
Matching: 3
In-Place: 1
Your Guess? verse
Matching: 2
In-Place: 2
Your Guess? vague
Matching: 4
In-Place: 4
Your Guess? vogue
Correct! You got it in 6 guesses.

Sample Run

Cinco! Sample Solution
by Steve J. Hodges
I'm thinking of a five letter word...
Your Guess? draft
Matching: 2
In-Place: 1
Your Guess? xxxxx
Secret Word is: credo
Your Guess? greed
Matching: 3
In-Place: 2
Your Guess? credo
Correct! You got it in 4 guesses,
but only by cheating.

What to turn in

For this assignment, you will be creating a project with several files. All of your project files should be placed in a directory named 20j-5 inside your home directory on Pengo. This directory should not contain any files not part of your project, nor should it contain any subdirectories or binaries. It's okay to leave cinco-words.txt in this directory. I will collect all of the files from this directory.