Compsci 100, Spring 2012, Hangman

See the howto pages for details on creating projects, files, and so on. The pages here describe in broad strokes what this assignment is about.

Hangman is a traditional children's game, typically played with words. It's possible, however, to play Category Hangman --- rather than guessing words the player might guess names of cities, or athletes, or fictional characters, or Duke professors or top forty song titles --- the list is endless.

You'll be writing a program to play a "guess a word letter-by-letter" version of hangman as shown below. You'll also be doing some statistical analysis of the words used in the Hangman game.

This assigment is very similar to the hangman assignment in CompSci 6, but with the addition of an analytical part.

Goals

Overview

Part 1a: Statistical/Forensic Analysis

You're given a class HangmanFileLoader.java which you use in the game to get a word the user will guess. See the howto for details. For this first part of the assignment you'll add to code started for you in HangmanStats.java to answer one question we ask and to ask and answer another question you decide on.

We want you to estimate the number of different words there are of 4, 5, 6, and so on up to 20 letters long. You can do this by repeatedly calling HangmanFileLoader.getRandomWord(6), for example, and adding the returned word to a set. The size of the set is an estimate of the number of words of length 6. See the howto for more details.

Part 1b: Your Own Question

You should also pose your own question about the words and the code that generates the random words of a specific length in HangmanFileLoader. You should also write code to answer your question and include the data in the analytical writeup you turn in. You could, for example, wonder how many calls are needed before some word is returned that was previously returned . You could write code to determine this. Any question you write is fine, but you must write code to answer the question. You're welcome to come up with 'extra' questions (up to three) that you don't write code for, but which you'd like to be able to answer/write code to answer. Include all questions in your analytic writeup.

Part 2: Hangman Game

Write a program to play a console-based, word-oriented game of hangman. The user should be allowed to specify the number of letters in the word and the number of misses until the game is lost (see the sample runs below for details). The program should be reasonably robust in the face of faulty input from the user, though don't go overboard in writing code to protect against bad input.

One detail you should consider is duplicate letters. If you have already guessed 'e' and then you guess 'e' again, that should not cost you a guess.

Details and guidelines of how to organize the program, including the methods you should write, are describd in the howto pages.

Sample Run

Here's a sample run of Hangman. You do not need to follow the format exactly, but you should include with each turn the player takes the following information:

In the run below the user input is in italics, the other text is printed by the program.


# letters in word:  8
# guesses to hanging:  7
_ _ _ _ _ _ _ _
misses left:  7
guesses so far:  
guess letter:  e
no e
_ _ _ _ _ _ _ _
misses left:  6
guesses so far:  e 
guess letter:  a
no a
_ _ _ _ _ _ _ _
misses left:  5
guesses so far:  a e 
guess letter:  o
no o
_ _ _ _ _ _ _ _
misses left:  4
guesses so far:  a e o 
guess letter:  u
no u
_ _ _ _ _ _ _ _
misses left:  3
guesses so far:  a u e o 
guess letter:  i
_ _ _ i _ _ i _
misses left:  3
guesses so far:  a u e o 
guess letter:  s
no s
_ _ _ i _ _ i _
misses left:  2
guesses so far:  a e o s u 
guess letter:  t
no t
_ _ _ i _ _ i _
misses left:  1
guesses so far:  a e o s u t 
guess letter:  r
_ _ r i _ _ i _
misses left:  1
guesses so far:  a e o s u t 
guess letter:  n
no n
you are hung :-(, secret word is  cyrillic

Submit using the submit name hangman.

Grading

You get a 0-4 grade on your analytical write-up, a 0-4 grade on the quality of the game played with your program (does it display the 3 things we asked for in the sample run, do you handle duplicate letters correctly, is the output reasonable), and a 0-2 grade based on the style of the code you write (see the CS100 style guidelines for what we will be checking in terms of good style) . For this assignment robustness in the face of user errors is NOT important. Don't worry about writing code, for example, to make sure the user enters a number if you ask for the number of letters in the to-be-guessed word.

Extra Credit

Words are kind of old, offer the user the choice of playing hangman in more than one category, reading "words" from files you provide, e.g., instead of words use actors, books, and so on.