Packages

class GameState extends AnyRef

Each instance of class GameState represents a single state within the Peeveli variant of Hangman: 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? Moreover, our dishonest hangman needs an additional piece of information: Which words are still credible solutions given the earlier guesses?

Chapter 9.3 of the ebook has a detailed discussion of the internal logic of the Peeveli game.

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.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. GameState
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new GameState(missesAllowed: Int, length: Int, vocabulary: Vector[String])

    Creates a new GameState that represents the initial state of a new game of Peeveli.

    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 (see optional materials in Chapter 4.1). You don’t need to use it.

    missesAllowed

    the number of incorrect guesses the guesser is allowed to make

    length

    the number of characters in the target word that the guesser will look for

    vocabulary

    a collection of known words; all words of exactly length characters in the vocabulary are potential target words

  2. new GameState(missesAllowed: Int, previousGuesses: String, visibleWord: String, possibleSolutions: Vector[String])

    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

    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").

    possibleSolutions

    all the words in the game's vocabulary that match the visibleWord parameter and are therefore plausible correct solutions

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  9. def guessLetter(guess: Char): GameState

    Returns a new GameState that follows this current one given that the guesser guesses a particular letter.

    Returns a new GameState that follows this current one given that the guesser guesses a particular letter. The rationale behind moving from one state to another is described in Chapter 9.3 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.

    guess

    a guessed letter; this can be in either case but is always interpreted as an upper-case character

    returns

    the state of the game after the newest guess

  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. def isLost: Boolean

    Returns true if the player has missed with more guesses than allowed and has therefore lost the game; returns false otherwise.

  13. def isWon: Boolean

    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 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.

  14. val missesAllowed: Int
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. def numberOfSolutions: Int

    Returns the number of all known words that are (still) possible solutions to this game of Peeveli, given the guesses that have already been made.

  19. val possibleSolutions: Vector[String]
  20. val previousGuesses: String
  21. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  22. def toString: String

    Returns a string description of the game state.

    Returns a string description of the game state.

    Definition Classes
    GameState → AnyRef → Any
  23. val visibleWord: String
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  27. def wordLength: Int

    Returns the length of the target word.

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from AnyRef

Inherited from Any

Ungrouped