Each instance of class GameState represents a single state within the Peeveli variant of Hangman. Such a state consists of the following information:
What does the (partially visible) target word look like to the guesser?
How many incorrect guesses can the guesser still make?
Which guesses have already been made?
Our dishonest hangman also needs to know: Which words are still credible solutions, given the earlier guesses?
Chapter 10.2 of the ebook details the Peeveli game’s internal logic.
While a player plays a game of Peeveli, the game will move from one state to another. Even so, each GameState object is immutable. Each successive state is represented by a new GameState object, which is generated by calling the current state’s guessLetter method.
Parameters
missesAllowed
the number of incorrect guesses that the guesser can still make before losing the game. A negative number means that the game is over.
previousGuesses
a string that contains all the previously guessed characters in order
viableSolutions
all the words in the game’s vocabulary that match the visibleWord parameter and are therefore plausible correct solutions
visibleWord
the version of the target word that is visible to the guesser. In a state that represents the beginning of the game, this will consist of unrevealed characters only (e.g., "_____"); see Unrevealed. In later states, more and more characters will be visible (e.g., "C___O").
Creates a new GameState that represents the initial state of a new game of Peeveli. All the letters of the target word are unrevealed.
Creates a new GameState that represents the initial state of a new game of Peeveli. All the letters of the target word are unrevealed.
Note to students: This is an additional constructor for the class. You don’t need to use it. (Additional constructors are introduced in an optional section of Chapter 4.4.)
Parameters
length
the number of characters in the target word that the guesser will look for
missesAllowed
the number of incorrect guesses the guesser is allowed to make
vocabulary
a collection of known words; all words of exactly length characters in the vocabulary are potential target words
Returns a new GameState that follows this current one, given that the guesser guesses a particular letter. The rationale for moving from one state to another is described in Chapter 10.2 of the ebook.
Returns a new GameState that follows this current one, given that the guesser guesses a particular letter. The rationale for moving from one state to another is described in Chapter 10.2 of the ebook.
The next GameState will certainly have one more letter in previousGuesses than the present one. In addition, it may have more visible letters in the target word, fewer misses allowed, and/or fewer potential solutions remaining.
The player will always spend a missed solution attempt if the guess did not reveal any new letters. This happens even if the player had already guessed the same letter before.
Parameters
guess
a guessed letter; this can be in either case but is always interpreted as an upper-case character
Returns true if the guesser has won the game, that is, if they haven’t missed too many times and all the letters in the target word are visible. Returns false otherwise.
Returns true if the guesser has won the game, that is, if they haven’t missed too many times and all the letters in the target word are visible. Returns false otherwise.