CS21 Lab6: Design a solution for the game Ghost

Due 11:59pm Tuesday, October 26, 2010

This week's lab is part of a two-part assignment where you will first design and then implement a more complex program. A skeleton version of the program ghost.py will appear in the directory cs21/labs/06 when you run update21 in a terminal window. The program handin21 will only submit files in this directory.

You may work with one partner on this lab. If you work with a partner, put your name and the name of your partner in the list of authors at the top of your program. Only one partner needs to run handin21 to submit the files for the group. Both partners will receive the same grade.

Introduction

Over the next two weeks, you will write a program that plays the word game Ghost. For Lab 6, you will focus on using top-down design to create the overall structure of the program. Once your proposed structure has been reviewed, then for Lab 7 you will focus on using bottom-up implementation and unit testing to incrementally construct the program.

Ghost is a word game where players take turns adding letters to a growing word fragment, trying to avoid being the one to actually spell a valid word. However, the word fragment must always be the start of some valid word. If a player doesn't believe that the current fragment could make an actual word, he or she may challenge the other player to produce a valid word from the fragment. A player wins by forcing the other player to add a letter that spells a complete word. A player can also win by challenge. One additional constraint is that any word of three letters or fewer does not count. To make things more concrete let's consider a couple of examples.


Examples

Suppose that you are playing with a friend.

You decide to play again, but this time the friend wants you to go first.

Your friend decides to give it one more try, and it's his turn to start.

For this lab, instead of playing against a friend you will be playing against the computer. This is much more challenging because the computer has access to a complete dictionary of words. Here are a few sample runs showing how your program might work.

Sample Runs
Welcome to the game of Ghost.
The current word fragment is: h

1. Add a letter 
2. Challenge
Choice: 1

Enter a letter: e
The current word fragment is: he

Computer will add the letter: m
The current word fragment is: hem

1. Add a letter 
2. Challenge
Choice: 1

Enter a letter: l
The current word fragment is: heml

Computer will add the letter: o
The current word fragment is: hemlo

1. Add a letter 
2. Challenge
Choice: 1

Enter a letter: c
The current word fragment is: hemloc

Computer will add the letter: k
Computer just made the word hemlock

Congratulations, you just outsmarted the computer!

Notice in the above example that the three-letter word hem appeared, but the computer did not lose the game, this is because only words of length four or longer count.

Welcome to the game of Ghost.
The current word fragment is: r

1. Add a letter
2. Challenge
Choice: 1

Enter a letter: o
The current word fragment is: ro

Computer will add the letter: m
The current word fragment is: rom

1. Add a letter
2. Challenge
Choice: 1

Enter a letter: b
The current word fragment is: romb

Computer challenges!
romb is NOT the start of any valid word.

Sorry, you lose.


Requirements
For Lab 6, you must turn in just your top-down design for a solution to this game.

Here is an example of a stubbed out program. What you turn in for this lab should be similarly structured.

Helpful tips
Submit

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