020_Assignment_0_Hangman

# 020_Assignment_0_Hangman - CS106L Fall 2009 Handout#02...

This preview shows pages 1–2. Sign up to view the full content.

Fall 2009 Handout #02 October 22, 2009 Assignment 0: Evil Hangman _________________________________________________________________________________________________________ Due November 5, 11:59 PM Introduction It's time to pull together your newfound C++ skills to build an incredibly duplicitous piece of software: Evil Hangman . Your task is to construct a computer program that fools mortals like you and I into thinking we're playing a simple game of Hangman while in reality we're facing the full power of a silicon foe. Normally, the game Hangman is played as follows: 1. One player chooses a secret word, then writes out a number of dashes equal to the word length. 2. The other players begin guessing letters. If a player guesses a letter that's in the word, the first player reveals all instances of that letter in the word. Otherwise, the guess is incorrect. 3. The game ends either when all the letters in the word have been revealed or when the guessers have run out of guesses. Fundamental to the game is the fact the first player accurately represents the word she has chosen. That way, when the other players guess letters, she can reveal whether that letter is in the word. But what hap- pens if the player doesn't actually choose a word? What if instead that player just comes up with a list of every possible word that could fit in the spaces , then starts eliminating words based on the other players' guesses? Provided that the player choosing the word can do this quickly enough, the other players would almost certainly lose but would have no idea that anything suspicious was afoot. Let's illustrate this technique with an example. Suppose that you are playing Hangman and it's your turn to choose a word, which we'll assume is of length four. Rather than choosing a word, instead you build a list of all of the four-letter words in the English language. For simplicity, let's assume this is your word list: ALLY BETA COOL DEAL ELSE FLEW GOOD HOPE IBEX Now, suppose the other players guess the letter E. We can perform one of two possible actions. First, we can simply eliminate all words that contain E and tell the other players that they guessed incorrectly. For example, if we decide to remove all words containing E from the list, then our word list would become ALLY COOL GOOD However, removing all words containing the guessed letter from the word list might not be a good idea. For example, given these three words as a word list, if the user were to guess O, removing all words con- taining the letter O would give us a length-one word list. If we instead remove all words not containing O from the list, then we get the following list: COOL GOOD Which has two words instead of one. - 1 -

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

020_Assignment_0_Hangman - CS106L Fall 2009 Handout#02...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online