CS19 Fall 2016
Assignment 4 (Cinco )
Make sure to save time to test your program, some of these functions will be tricky to code!
In this program, you will be creating a word guessing game called Cinco, except that in your program the computer will guess the words, not a human player!
In this game, the human will pick a (legal) secret five letter word from the list of legal secret words. The computer 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 provided1 (click this link to get the word list). Note, that the program can be run with different length word lists.
I suggest making your own (very short) word lists to greatly simplfy your initial testing!
The file will always consist of five-letter words, one per line, all in lowercase and in alphabetical order. Your program will always read its word list from a file named cinco-words.txt.
Each round, the computer guesses a word from its list of words. After the computer guesses, the human enters the number of letters in the guess that also exist in the secret word and how many of those letters are in the correct spot. If the score is five and five, then the computer has guessed your secret word and the game ends, printing out how many guesses it took the computer to win. If the socre is less than five and five, the computer will update its Dictionary (by removing one or more words from its word list) and then makes its next guess. If the computer runs out of words to guess, it will inform the player that they must have made a mistake or cheated. Some sample runs are provided below.
Any letter in your secret word should only be matched once. For example,
Your secret word: fable
Computer's guessed word: eagle
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 word from the list (for each guessed word by the computer,) and removing one or more words from the list after the computer's guess (this is the hardest part of the assignment.) It should also include one or more helper functions since removing words from the list involves several steps.
Secret words must have five different letters. For example, eagle is a valid guess, but not a valid secret word.
The other class, named Cinco, will keep track of the game state, handle the user input and output, and contain the main function. The main game loop (which will include all human i/o over STDIN and STDOUT) must be in a function named consoleUI(). A required main() function for the Cinco class is provided.
Your output must 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!
[steveh@pengo ~]$ ./p4 CS19 Cinco with Computer Guessing Example by Steve J. Hodges Select your five letter word from the list... I'm guessing: whole Matching? 1 In-Place? 1 I'm guessing: wreck Matching? 2 In-Place? 0 I'm guessing: ruddy Matching? 1 In-Place? 0 I'm guessing: super Matching? 4 In-Place? 1 I'm guessing: gripe Matching? 3 In-Place? 1 I'm guessing: stoke Matching? 2 In-Place? 2 I'm guessing: petri Matching? 3 In-Place? 1 I'm guessing: revel Matching? 2 In-Place? 0 I'm guessing: spare Matching? 5 In-Place? 5 I got it in 9 guesses. [steveh@pengo ~]$
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 19-4 inside your home directory on Pengo. This directory should not contain any files not part of your project, nor should it contain any subdirectories. I will collect all of the files from this directory.
1. The file cinco-words.txt has also be copied to your home directory on Pengo.