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

CS19 Fall 2018

Assignment 5 (Cinco!)

Directory Name

19-5

Resulting Executable (from your Makefile)

p5

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 only a legal secret word if it appears in the Dictionary and is also comprised of five different distinct letters. A word list of about 2400 five letter words is provided1 (click this link to get the word list). The file will always consist of words, one per line, in alphabetical order, all in lowercase.

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

Each round, the player guesses a word. If the guess is correct, the computer reports how many guesses it took 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.

You should use C++ style strings for this assignment

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 (plus your "main function"). One class, named Dictionary, will take care of inputting and storing the words, selecting a random word from the list, and looking up words to verify that they are in the dictionary. The words file must be named cinco-words.txt (this will allow me to easily use different files durring testing.) Your Dictionary will use a Set<string> container for efficient lookup. The function that selects a random word 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, and handling the user input and output. Some starter code is provided. Use of the provided code is optional (except for main, which is required.) You may use it as is, modify it, or discard it. If you come up with your own design, then your program architecture will be part of your overall evaluation.

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

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!

Sample Run

CS19: 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

CS19 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, including your makefile (with make clean option,) should be placed in a directory named 19-5 inside your home directory on Pengo. This directory should not contain any files not part of your project, and it should not 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.

1. The file cinco-words.txt has also been copied to your home directory on Pengo.