Sun 3/18 Submission instructions with the link to the Google form to use are shown at the bottom of the page in blue.
Tues 3/20 Sample output replaced below, to help with people who still have end of game word deletion issues.
Write a program to play hangman where the computer chooses the word and the human user tries to guess the word. The twist is that the computer starts out with a dictionary of many words. After each human guess, the computer eliminates all words containing the letters guessed so far, making the word as hard to find as possible. Correct user guesses only show up once the list has been narrowed down so far that all remaining words have the letter that the user guesses. [Inspired by the SIGCE Nifty Assignment by Keith Schwartz.]
For the version that you turn in include the debugging information as illustrated below so that we can verify your program is working correctly. A sample of running this program is shown below (though it was originally made with a different dictionary, so your numbers will likely be different):
Author: Dale Reed Class: CS 141, Spring 2018 Lab: Mon 5am Program: #4, Twisted Hangman Xcode on a Mac Welcome to Hangman. First you will need to choose which length word you want. Then you will have 15 letter guesses to try and match all the letters in the word. Starting with 40437 words. What length word do you want? 5 Now we have 3538 words of length 5 15. Letters used so far: Letters found: _ _ _ _ _ Guess a letter: a Now we have 2150 words. 14. Letters used so far: A Letters found: _ _ _ _ _ Guess a letter: e Now we have 1056 words. 13. Letters used so far: A E Letters found: _ _ _ _ _ Guess a letter: i Now we have 642 words. 12. Letters used so far: A E I Letters found: _ _ _ _ _ Guess a letter: o Now we have 230 words. 11. Letters used so far: A E I O Letters found: _ _ _ _ _ Guess a letter: u Now we have 15 words. 10. Letters used so far: A E I O U Letters found: _ _ _ _ _ Guess a letter: ~ CRYPT CYSTS DRYLY FLYNN GYPSY HYMNS LYMPH LYNCH MYRRH MYTHS NYMPH PYGMY SHYLY TRYST WRYLY 10. Letters used so far: A E I O U Letters found: _ _ _ _ _ Guess a letter: y You found letter Y Now we have 3 words. 9. Letters used so far: A E I O U Y Letters found: _ _ Y _ _ Guess a letter: ~ CRYPT FLYNN TRYST 9. Letters used so far: A E I O U Y Letters found: _ _ Y _ _ Guess a letter: f Now we have 2 words. 8. Letters used so far: A E F I O U Y Letters found: _ _ Y _ _ Guess a letter: ~ CRYPT TRYST 8. Letters used so far: A E F I O U Y Letters found: _ _ Y _ _ Guess a letter: s Now we have 1 words. 7. Letters used so far: A E F I O S U Y Letters found: _ _ Y _ _ Guess a letter: ~ CRYPT 7. Letters used so far: A E F I O S U Y Letters found: _ _ Y _ _ Guess a letter: c You found letter C Now we have 1 words. 6. Letters used so far: A C E F I O S U Y Letters found: C _ Y _ _ Guess a letter: r You found letter R Now we have 1 words. 5. Letters used so far: A C E F I O R S U Y Letters found: C R Y _ _ Guess a letter: p You found letter P Now we have 1 words. 4. Letters used so far: A C E F I O P R S U Y Letters found: C R Y P _ Guess a letter: t You found letter T Now we have 1 words. Letters found: C R Y P T *** Congratulations! Well done!
Your program must work with dictionary of different sizes. This means you need to either read the file twice (first time to find the size), or use some sort of dynamically sized storage such as a vector. Start with figuring out how to store the dictionary of 58528 words stored in dictionary.txt. You can refer to the macbeth.cpp program that we saw in class as an example of how to read from a file. When you read in words from the dictionary convert everything to uppercase so that your word and letter comparisons work correctly. Also eliminate words containing punctuation (e.g. "actor's") and convert all words to upper-case.
Start with 15 turns. On each turn display the number of words we are (still) working with. (If you want to make a copy for your friends then you will want to remove this part of the display.) Also display the characters the user has guessed so far, as well as any letters in the word that have been correctly guessed.
Each time the user guesses a letter the computer removes from the words list all words containing that letter. Eventually this no longer works, as eliminating all words with a particular letter means there are no words remaining. At this point the computer finds the first word on the list and displays the user's guessed character in the position in which it is found in that word. At this point you must also eliminate any words that have duplicates of that letter in some additional position as compared to this first word on your word list.
The computer still tries to be tricky, however, so it will also keep any other words still on the list that also have that letter in that position.
Giving input of '~' results in a "cheat" where the computer displays all words that are still possibilities.
All letters must be guessed individually. Because of the way the program works, this includes having to individually enter multiple copies of the same letter near the end of the game. In other words, if the final word has two 'T' letters, then you will need to enter 'T' twice. Once the program has to start displaying letters, it must display all occurrences of any guessed letter. Note that this will affect which other words are still possibilities.
Up to 10 points extra credit if you create a graphical version of the program that either takes input from the text-based version (up to 5 points) or is completely graphical (up to 10 points). In both cases your program must draw the hangman figure as each guess is made of letters not on the board. If you implement the graphical version, plan on demonstrating it in person to the TA to be graded.
You may not submit a program into both the regular submission as well as the extra credit submission. If you do, you will not be eligible for any extra credit points. Submit your extra credit program using the same naming conventions shown below, into the Blackboard assignment Program 4 Extra Credit.
Inside your program itself you must include the following grading rubric, just below your header documentation, as shown below. We will use this when grading your program as a place to annotate and list any deductions taken off within each category. Note that this is in your code but is within a comment block so should not appear on the screen when you run your program.
/* ------------------------------------------------ reedProg4.cpp Program #4: Twisted Hangman Program delays choosing which word is chosen, making the game as difficult as possible.
Class: CS 141 Author: Dale Reed Lab: Tues 5am System: C++ Mac Xcode Grading Rubric: 50 Execution points 2 Displays header info and instructions on screen when run 5 Correctly counts and displays the number of initial dictionary words, for any dictionary 10 Correctly extracts words of the selected length and displays count for those words, < 5 seconds 3 Move number is displayed and updates correctly. Move number starts at 15. 2 Handles upper and lower-case user input for the letters that are guessed 3 Displays letters guessed so far, in alphabetical order 10 Updates number of words left after each guess 5 Input of '~' displays all possible words remaining 10 Correctly displays letters once all words remaining have that letter, eliminating non-match words 5 Displays appropriate message when word is guessed, or when it is not guessed and guesses run out
45 Programming Style (Given only if program runs substantially correctly) 5 Program naming convention is followed 10 Meaningful identifier names 10 Comments: Has header and this rubric. Has comments on each block of code 10 Appropriate data and control structures 10 Code Layout: Appropriate indentation and blank lines ------------------------------------------------ */
Note that the last 5 points for credit on this program will come from your peer review. Instructions on what to do for this will be posted in Piazza after the program deadline.
Once you are ready to turn in your program you will need to make a copy of your .cpp file and on the copy change the extension to be doc instead of cpp. The name of the program you will turn in should be your netid followed by Prog4 and this .doc file extension. In other words, if your netid is reed then your program would be called reedProg4.doc If you choose to work with a partner, remember you must register both your names at least one week before the deadline. If you do work with a partner then include both your netids in the program name separated by an underscore, such as: reed_patelProg4.doc
We will be using a Google form to submit program 4. Using a google form you only get one chance to include a file, so verify your program before submitting!
For program 4 you should not zip up your program, but instead turn in the .doc file (renamed from the original .cpp file) directly without zipping it.
Failing to follow these naming conventions will result in a 5 point deduction.
To submit use this Google form
Once the on-time deadline has passed, use this Google form for LATE submissions only. Note the late program deadline is during spring break.