# CS21 Lab 7: Top-Down Design: word warp

Top-Down Design due first (Oct 31)!!!
Due 11:59pm Sat, 7 Nov 2015

Please read through the entire lab before starting! Also, as always, run update21 to create your cs21/labs/07 directory and create your programs for lab 7 in this directory.

Word Warp

Our lab this week and next is to write a game similar to Word Warp. This is a word game where the user is given 6 letters and has to make as many 4, 5, and 6-letter words as possible from the given letters. For example, given the letters BTALTE, you can make 'tablet', 'belt', 'able', and so on...

For this lab you will use top-down design. We are giving you two weeks to complete this program. However, we require your initial top-down design due this Saturday (Oct 31) and the full implementation the following week (Nov 7).

Remember, for the design of a program, you should have:

• main() completely written
• functions called from main() all stubbed out with parameters, comment, and a return statement
• clear use of data structures and variables in main() and the stubbed-out functions
• a design that runs without errors (although it doesn't play the game yet)
Here is a simple example of a top-down design.

Examples, Requirements, and Tips

Here are some examples of word warp games to help you see how the game works:

Special proceedures for this two-week lab:

• create design-ww.py first (should have main() done, all function stubs written, should run but not do anything)
• after you have a working design, run handin21 to turn it in! Then, send your professor a short email, letting them know your design is done. We will take a look at each design and send you comments (usually within a day or two).
• after you have the design done, and have heard back from your professor, copy the file to ww.py (cp design-ww.py ww.py) and implement the full game

You have some freedom in how you want your game to look. Here are our requirements for the game:

• user keeps entering words until no words are left or they want to quit
• user may quit at any time
• allow user to shuffle the given letters (with WW)
• only 4-6 letter words allowed
• pick random 6-letter word to start game (and shuffle the letters)
• use the system word list in /usr/share/dict/words
• keep track of words played
• don't allow invalid words (must be makeable with given letters and a valid English word)
• keep score (higher points for longer words)
• find all possible words and use to display how many words are left

Here are a few tips you may find useful...

• to shuffle a python list, use the shuffle() function in the random library
• to convert between strings and lists, you can use list() and join():
>>> S = "hello!"
>>> L = list(S)
>>> print L
['h', 'e', 'l', 'l', 'o', '!']
>>> "".join(L)
'hello!'

• the system word list (/usr/share/dict/words ) is just a text file you can open and read in
• one way to find all possible words given 6 letters: search through the system word list, one word at a time, and decide if that word can be made with those letters. Here's an example, trying to make the word "boot" from the letters "bcbato":
       letter   number in "boot"     number in "bcbato"
------   ---------------      -----------------
b          1                    2
o          2                    1   <-- not enough!
o          2                    1   <-- not enough!
t          1                    1

• make use of the python str methods: strip(), lower(), isalpha(), islower(), count(), etc
• some of the words in /usr/share/dict/words have non-alphabetic characters in them, such as accents and apostrophes. It is fine for this game if you just ignore all non-alphabetic words:
>>> word = "pony"
>>> word.isalpha()
True
>>> word = "doesn't"
>>> word.isalpha()
False

Optional Challenges

Here are a few optional challenges for this game. If you do these (just for fun, no extra points!), please copy your working game to a new file: cp ww.py ww-extra.py

• if the user gets all the words, give them another word to play, so they can get an even higher score
• allow users to specify the word length range at the beginning of the game (ex: minlen=3, maxlen=8, instead of 4-6)
• some words, like "arches", have so many possible words (40) that the game is not fun. Make your program use only words that have from 6-15 possible words.
• pick and mark in some way a special word in the list of possible words, such that, if the user guesses that special word, they get a 10-point bonus added to their next 3 words
Submit

Once you are satisfied with your program, hand it in by typing handin21 in a terminal window.