next up previous
Next: A Template For hangman-guess Up: Project 2 Description Previous: Project 2 Description

Hangman

From How to Design Programs: An Introduction to Programming and Computing by Matthias Felleisen, Robert Bruce Findler, Matthew Flatt and Shriram Krishnamurthi of Rice University

Hangman is a game where one player thinks of a word and draws a gallows. The other player tries to guess the word by guessing a letter at a time. If the player correctly guesses a letter, the first player reveals where in the word that letter occurs. If the player's guess in incorrect, the first player adds another part of a body to the gallows. The game ends when either an entire body is on the gallows (in which case the first player wins) or when every letter of the word is guessed.

Below are the data definitions for letters, words and body-parts. The definition for words is incomplete and is only meant as a guideline.

Some constants are:

The first player is your hangman program. It randomly selects a word from the WORD dictionary and allows the user to guess. Here are the responses that the program will provide:

  1. (list "Congratulations! You Won!" word)
  2. (list "Game Over" word)
  3. (list "Good Guess!" word-so-far)
  4. (list "Sorry, no'' guess ``in `` word-so-far body-part-lost)

Now, let's look at an example run where the procedure (hangman) choses the initial word and (hangman-guess guess) determines which of the four responses is appropriate given the guess and the word.

The dialog shows two rounds of hangman. The player loses the first round of hangman. Also, while a first guess of 'a yields a positive Good Guess! the second guess of 'a yields a lost body part (since 'a had already been guessed). The second round of hangman begins with a call to hangman which resets the game and chooses a new word. The round is won by the player.


next up previous
Next: A Template For hangman-guess Up: Project 2 Description Previous: Project 2 Description
Patricia Gilfeather 2001-04-12