Our assignment is to write a computer program which plays a game of Hangman using this “Evil Hangman” algorithm. In particular, our program will do following:
1. Read the file dictionary.txt, which contains the full contents of the words list.
2. Prompt the user for a word length, reprompting as necessary until he enters a number such that there's at least one word that's exactly that long. That is, if the user wants to play with words of length -42 or 137, since no English words are that long, we should reprompt him.
3. Prompt the user for a number of guesses, which must be an integer greater than zero.
4. Prompt the user for whether he wants to have a running total of the number of words remaining in the word list. This completely ruins the illusion of a fair game that we'll be cultivating.
Evil Hangman algorithm:
1. Constructing list of all words in the English language whose length matches the input length.
2. Printing out how many guesses the user has remaining, along with any letters the player has guessed and the current blanked-out version of the word. If the user chose earlier to see the number of words remaining, print that out too.
3. Prompting the user for a single letter guess, reprompting until the user enters a letter that he hasn't guessed yet.
4. Partitioning the words in the dictionary into groups by word family.
5. Finding the most common “word family” in the remaining words, remove all words from the word list that aren't in that family, and report the position of the letters (if any) to the user. If the word family doesn't contain any copies of the letter, subtract a remaining guess from the user.
6. If the player has run out of guesses pick a word from the word list and display it as the word that the computer initially “chose.”
7. If the player correctly guesses the word, congratulate him.
6. Ask if the user wants to play again and loop accordingly.
We use associative arrays for this purpose.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.