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

CS19 Spring 2019

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, all in lowercase.

Since selecting a secret word randomly from a set is tricky, you will also use a vector to store only words that are legal secret words. (The set will 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. 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.

Your program should use a default of "cinco-words.txt" as the name of the word file list for your Dictionary, unless a file name is provided on the command line (in which case, use that filename instead.)

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

[steveh@pengo cpp]$ ./p5
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.
[steveh@pengo cpp]$

Sample Run

[steveh@pengo cpp]$ ./p5 mywordlist.txt
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.
[steveh@pengo cpp]$

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.