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.
Text Twist
Our lab this week and next is to write a game similar to
Text Twist.
This is a word game where the user is given 7 letters and has to make
as many words as possible from the set of 7 letters. For example, given the letters
peeteds, you can make 'deepest', 'speed', 'pets', 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 Friday (Mar 22) and the full implementation
the following Friday (Mar 29).
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 text twist games to help you see how the game works:
You have some freedom in how you want your game to look. Here
are our requirements for this game and lab:
- create design-tt.py first (should have main() done, all function stubs, should run but not do anything)
- after you have the design done, copy the file to tt.py and implement:
cp design-tt.py tt.py
- user keeps entering words until no words left or they want to quit
- user can quit at any time
- allow user to shuffle the letters
- only 4-7 letter words allowed
- pick random 7-letter word to start game (and shuffle the letters)
- use the system dictionary in /usr/share/dict/words
- keep track of words played
- don't allow invalid words (must be makable with given letters and a valid English word)
- keep score (higher points for longer words)
- display score-dependent message at end
- find all possible words and use to determine number of words left and best-possible score
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 dictionary (/usr/share/dict/words ) is just a text file you can open and read in
- one way to find all possible words given 7 letters: search through the dictionary, one word at a
time, and decide if that word can be made with those letters
Submit
Once you are satisfied with your program, hand it in by typing
handin21 in a terminal window.