Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

current : Overview: The Game of (Evil) Hangman Sample execution log In the game of hangman, one player in our case, a Welcome to the

image text in transcribedimage text in transcribedimage text in transcribed

current : Overview: The Game of (Evil) Hangman Sample execution log In the game of hangman, one player in our case, a Welcome to the cse143 hangman game. computer) picks a word that another player the user) is trying to guess. The guesser guesses individual let- What length word do you want to use? 4 ters until the word is fully discovered in which case the How many wrong answers allowed? Z guesser wins) or a specified number of incorrect letters is guessed (in which case the guesser loses). As correct guesses: 7 letters are guessed, their location in the secret word is guessed: 0 revealed to the guesser. You can learn more about the current : game of hangman on its Wikipedia page. (This game Your guess? Sorry, there are no e's has been the inspiration for many other games, including the popular American gameshow Wheel of Fortune.) guesses : 6 guessed: (e) In our EVIL! game of hangman, the computer delays picking a specific secret word until it is forced to do so. Your guess? 2 As a result, the computer is always considering a set of Yes, there are 2 o's words that could be the secret word. In order to fool the user into thinking it is playing fairly, the computer only considers words with the same letter pattern. guessed: [e, o) current : -OO- Your guess? For example, suppose that the computer knows the fol- Sorry, there are no d's lowing words: ally beta cool deal else flew good hope ibex guesses: 5 guessed: [d, e, o] In our game, instead of beginning by choosing a word, current : -OO- the computer narrows down its set of possible answers Your guess? as the user makes guesses. Yes, there is one c When the user guesses 'e', the computer must reveal guesses : 5 where the letter 'e' appears. Since it hasn't chosen a guessed: [c, d, e, o] word yet, its options fall into five families: current : COO- Your guess? 2 Pattern Family Yes, there is one 1 [ally, cool, good] answer - cool [beta, deal] You beat me [fleu, ibex] Chope] [else] guesses : 6 Page 1 of 6 The guess forces the computer to choose a family of words, but not a particular word in that family. The computer could use several different strategies for picking the family to display. Your program should always choose the family with the largest number of words. This strategy is reasonable because it leaves the computer's options open. For the example described above, the computer would pick ---- This reduces the possible answers it can consider to: ally cool good Hangman Manager Your HangmanManager class should have the following constructor: public HangmanManager (Collection dictionary, int length, int max) Your constructor is passed a dictionary of words, a target word length, and the maximum number of wrong guesses the player is allowed to make. It should use these values to initialize the state of the game. The set of words should initially contain all words from the dictionary of the given length, eliminating any duplicates. You should throw an IllegalArgumentException if the given length is less than 1 or if max is less than 0. You may assume the given Collection contains only non-empty strings composed entirely of low- ercase letters. Your HangmanManager class should also implement the following methods: public Set words() The client calls this method to get access to the current set of words being considered by the HangmanManager. public int guesses Left() The client calls this method to find out how many guesses the player has left. public Set guesses() The client calls this method to find out the current set of letters that have been guessed by the player public String pattern() The client calls this method to find out the current pattern to be displayed for the game, taking into account guesses that have been made. Letters that have not yet been guessed should be displayed as a dash and there should be spaces separating the letters. There should be no leading or trailing spaces. This operation should be "fast" in the sense that it should store the pattern rather then computing it each time the method is called. This method should throw an IllegalStateException if the set of words is empty. Save the pat- tern to avoid recomputation public int record (char guess) The client calls this method to record that the player made a guess. Using this guess, your method should decide what set of words to use going forward. It should return the number of occurrences of the guessed letter in the new pattern and it should appropriately update the number of guesses left. This method should throw an IllegalStateException if the number of guesses left is less than 1 or if the set of words is empty. If the previous exception was not thrown, it should throw an IllegalArgumentException if the character being guessed was guessed previously. You may assume that all guesses passed to the record method are lowercase letters. current : Overview: The Game of (Evil) Hangman Sample execution log In the game of hangman, one player in our case, a Welcome to the cse143 hangman game. computer) picks a word that another player the user) is trying to guess. The guesser guesses individual let- What length word do you want to use? 4 ters until the word is fully discovered in which case the How many wrong answers allowed? Z guesser wins) or a specified number of incorrect letters is guessed (in which case the guesser loses). As correct guesses: 7 letters are guessed, their location in the secret word is guessed: 0 revealed to the guesser. You can learn more about the current : game of hangman on its Wikipedia page. (This game Your guess? Sorry, there are no e's has been the inspiration for many other games, including the popular American gameshow Wheel of Fortune.) guesses : 6 guessed: (e) In our EVIL! game of hangman, the computer delays picking a specific secret word until it is forced to do so. Your guess? 2 As a result, the computer is always considering a set of Yes, there are 2 o's words that could be the secret word. In order to fool the user into thinking it is playing fairly, the computer only considers words with the same letter pattern. guessed: [e, o) current : -OO- Your guess? For example, suppose that the computer knows the fol- Sorry, there are no d's lowing words: ally beta cool deal else flew good hope ibex guesses: 5 guessed: [d, e, o] In our game, instead of beginning by choosing a word, current : -OO- the computer narrows down its set of possible answers Your guess? as the user makes guesses. Yes, there is one c When the user guesses 'e', the computer must reveal guesses : 5 where the letter 'e' appears. Since it hasn't chosen a guessed: [c, d, e, o] word yet, its options fall into five families: current : COO- Your guess? 2 Pattern Family Yes, there is one 1 [ally, cool, good] answer - cool [beta, deal] You beat me [fleu, ibex] Chope] [else] guesses : 6 Page 1 of 6 The guess forces the computer to choose a family of words, but not a particular word in that family. The computer could use several different strategies for picking the family to display. Your program should always choose the family with the largest number of words. This strategy is reasonable because it leaves the computer's options open. For the example described above, the computer would pick ---- This reduces the possible answers it can consider to: ally cool good Hangman Manager Your HangmanManager class should have the following constructor: public HangmanManager (Collection dictionary, int length, int max) Your constructor is passed a dictionary of words, a target word length, and the maximum number of wrong guesses the player is allowed to make. It should use these values to initialize the state of the game. The set of words should initially contain all words from the dictionary of the given length, eliminating any duplicates. You should throw an IllegalArgumentException if the given length is less than 1 or if max is less than 0. You may assume the given Collection contains only non-empty strings composed entirely of low- ercase letters. Your HangmanManager class should also implement the following methods: public Set words() The client calls this method to get access to the current set of words being considered by the HangmanManager. public int guesses Left() The client calls this method to find out how many guesses the player has left. public Set guesses() The client calls this method to find out the current set of letters that have been guessed by the player public String pattern() The client calls this method to find out the current pattern to be displayed for the game, taking into account guesses that have been made. Letters that have not yet been guessed should be displayed as a dash and there should be spaces separating the letters. There should be no leading or trailing spaces. This operation should be "fast" in the sense that it should store the pattern rather then computing it each time the method is called. This method should throw an IllegalStateException if the set of words is empty. Save the pat- tern to avoid recomputation public int record (char guess) The client calls this method to record that the player made a guess. Using this guess, your method should decide what set of words to use going forward. It should return the number of occurrences of the guessed letter in the new pattern and it should appropriately update the number of guesses left. This method should throw an IllegalStateException if the number of guesses left is less than 1 or if the set of words is empty. If the previous exception was not thrown, it should throw an IllegalArgumentException if the character being guessed was guessed previously. You may assume that all guesses passed to the record method are lowercase letters

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions