copyright Steve J. Hodges   http://steveh.net/cs19/cs19-hw04.html

CS19 Spring 2014

Assignment 4 (Unfun Word Game)

Directory Name

19-4

Resulting Executable

p4


Unfun

A word game that is no fun to play


Program Description

In this program, you will be creating a word guessing game called Unfun. In this game, the computer selects a five letter word from its Dictionary, and the user guesses letters of the alphabet. (Words in the Dictionary will always have five distinct letters.) The game ends when the user has guessed all five letters in the word, and the game tells the users how many guesses it took.

This game will be no fun to play because the computer will cheat (but without lying!) The computer won't actually pick a single word that user guesses but instead try to prolong the game as much as possible to force the user to make the largest number of guesses.

In order to do this, the computer will update the word list after each user guess, so that only legal words remain, and it will answer the users guesses with choices to keep the word list as long as possible

A word list of about 1600 lowercase five letter words is provided1 (click this link to get the word list). All of the words in this list have five distinct letters. Your program will always read its word list form a file named unfun-words.txt.

You may either use C++ style strings or C style strings for this assignment

Your output must match the style and formatting of the example, as the testing may be automated.

If the user enters the guess of '-' (a hyphen/minus sign) the program should reveal the current list of secret words as a comma seperated list . Using the cheat code should not count as a guess, should not terminate the program, and be reported upon at the end of the game. A sample run will be provided to illustrate how your program should work.

This program must be constructed using two classes. One class, named Dictionary, will take care of inputting and storing the words from a file, calculating counts of words with letters in a certain position (or not present at all,) and removing words from the list that don't have letters in a certain position. The other class, named Unfun, will take care of the game rules, keeping track of the game state, and handling the user input and output The main game loop (including i/o) must be in a function named play(). play() should be invoked from the main function in your main.cpp. Some notes with a suggested outline of your program is provided.. Use of the provided outline is optional. You may use it as is, modify it, or discard it. If you use your own structure, you will be evaluated on your program design.

Since this is a multi-file project, I will collect the directory 19-4 and all of its contents. You are required to ensure that only the necessary .h and .cpp files, a working makefile, and an optional readme.txt file are present. The binary program resulting from compiling your project should be called "p4". You will loose points if any other files are present, unless you have a 'make clean' option that removes them.

This is a program with many details. I strongly urge you to keep your program compiling and running at all stages of your project. Keep all your functions simple at first—the minimum to compile and run. Add code to one function at a time and test as you code. Start this project early! Have Fun!

Sample Run

[steveh@pengo2 Unfun]$ ./p4
CS19: Unfun! Sample Solution by Steve J. Hodges
I'm thinking of a five letter word,
you guess letters until you have the whole word!
The word: -----     previously guessed:
Guess #1? a
The word does not contain a(n) a.
The word: -----     previously guessed:a
Guess #2? b
The word does not contain a(n) b.
The word: -----     previously guessed:ab
Guess #3? c
The word does not contain a(n) c.
The word: -----     previously guessed:abc
Guess #4? d
The word does not contain a(n) d.
The word: -----     previously guessed:abcd
Guess #5? e
The word does not contain a(n) e.
The word: -----     previously guessed:abcde
Guess #6? f
The word does not contain a(n) f.
The word: -----     previously guessed:abcdef
Guess #7? g
The word does not contain a(n) g.
The word: -----     previously guessed:abcdefg
Guess #8? h
The word does not contain a(n) h.
The word: -----     previously guessed:abcdefgh
Guess #9? i
The word does not contain a(n) i.
The word: -----     previously guessed:abcdefghi
Guess #10? j
The word does not contain a(n) j.
The word: -----     previously guessed:abcdefghij
Guess #11? k
The word does not contain a(n) k.
The word: -----     previously guessed:abcdefghijk
Guess #12? l
The word does not contain a(n) l.
The word: -----     previously guessed:abcdefghijkl
Guess #13? m
The word does not contain a(n) m.
The word: -----     previously guessed:abcdefghijklm
Guess #14? n
The word does not contain a(n) n.
The word: -----     previously guessed:abcdefghijklmn
Guess #15? o
The word does not contain a(n) o.
The word: -----     previously guessed:abcdefghijklmno
Guess #16? p
The word does not contain a(n) p.
The word: -----     previously guessed:abcdefghijklmnop
Guess #17? q
The word does not contain a(n) q.
The word: -----     previously guessed:abcdefghijklmnopq
Guess #18? r
Yes, there is a(n) r.
The word: r----     previously guessed:abcdefghijklmnopqr
Guess #19? s
Yes, there is a(n) s.
The word: r-s--     previously guessed:abcdefghijklmnopqrs
Guess #20? t
Yes, there is a(n) t.
The word: r-st-     previously guessed:abcdefghijklmnopqrst
Guess #21? u
Yes, there is a(n) u.
The word: rust-     previously guessed:abcdefghijklmnopqrstu
Guess #22? v
The word does not contain a(n) v.
The word: rust-     previously guessed:abcdefghijklmnopqrstuv
Guess #23? w
The word does not contain a(n) w.
The word: rust-     previously guessed:abcdefghijklmnopqrstuvw
Guess #24? x
The word does not contain a(n) x.
The word: rust-     previously guessed:abcdefghijklmnopqrstuvwx
Guess #25? y
Yes, there is a(n) y.
Correct! You got the word "rusty" in 25 guesses.
[steveh@pengo2 Unfun]$ 

Sample Run

[steveh@pengo2 Unfun]$ ./p4
CS19: Unfun! Sample Solution by Steve J. Hodges
I'm thinking of a five letter word,
you guess letters until you have the whole word!
The word: -----     previously guessed:
Guess #1? e
The word does not contain a(n) e.
The word: -----     previously guessed:e
Guess #2? t
The word does not contain a(n) t.
The word: -----     previously guessed:et
Guess #3? a
The word does not contain a(n) a.
The word: -----     previously guessed:eta
Guess #4? o
The word does not contain a(n) o.
The word: -----     previously guessed:etao
Guess #5? a
You already guessed the letter a.
The word: -----     previously guessed:etao
Guess #5? i
The word does not contain a(n) i.
The word: -----     previously guessed:etaoi
Guess #6? n
The word does not contain a(n) n.
The word: -----     previously guessed:etaoin
Guess #7? s
The word does not contain a(n) s.
The word: -----     previously guessed:etaoins
Guess #8? h
The word does not contain a(n) h.
The word: -----     previously guessed:etaoinsh
Guess #9? r
The word does not contain a(n) r.
The word: -----     previously guessed:etaoinshr
Guess #10? d
The word does not contain a(n) d.
The word: -----     previously guessed:etaoinshrd
Guess #11? l
Yes, there is a(n) l.
The word: -l---     previously guessed:etaoinshrdl
Guess #12? u
Yes, there is a(n) u.
The word: -lu--     previously guessed:etaoinshrdlu
Guess #13? -
possible words: clump, pluck, plumb
The word: -lu--     previously guessed:etaoinshrdlu
Guess #13? p
Yes, there is a(n) p.
The word: plu--     previously guessed:etaoinshrdlup
Guess #14? c
The word does not contain a(n) c.
The word: plu--     previously guessed:etaoinshrdlupc
Guess #15? m
Yes, there is a(n) m.
The word: plum-     previously guessed:etaoinshrdlupcm
Guess #16? b
Yes, there is a(n) b.
Correct! You got the word "plumb" in 16 guesses.
(but you cheated)
[steveh@pengo2 Unfun]$ 

1. The file unfun-words.txt has also be copied to your home directory on Pengo.