CS21 Lab6: Lingo

Due 11:59pm Thursday, March 6, 2008

A skeleton version of the program will appear in this directory 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 assignment. 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.


For this assignment, you will write a program that implements the TV game show Lingo. The focus of this assignment is for you to practice using top-down design to construct your solution incrementally.

Lingo is a turn-based guessing game. The computer selects a random word and the player tries to guess the word. Each guess must also be a valid word of the same length (this is what makes the game interesting and hard). After a guess is made, the computer provides status information about how close (or how far) the player is to arriving at the solution. The status information includes which letters are correct, but in the wrong position, and which letters are correct, and in the right position.


To make things concrete, let's use an example where the computer is selecting a five-letter word. Normally, as a player of the game, you would not know what the computer had chosen. However, let's make things easier and peek at the computer's choice: guava.

It's time for you to begin guessing the word. Your initial guess is: spray. Notice that there is only one letter that you guessed that's also in the target word (the letter a). Rather than indicate the number of letters you have correct, the status message will specify which letters are exactly correct and which are in the sequence, but in the wrong place. You'll do this by UPPER-CASING the exact matches, leaving the 'inexact' matches alone, and replacing the wrong letters with dashes. So, in this case, where the letter a of your guess spray is an 'inexact' match, you'd receive the status message:

Clearly you don't know the word yet, so you make another guess: arrow. Again, the only correct letter is the a, and now it's in a different wrong place. So, the status you would receive is:

Your next guess is uvula. You continue to have the a in the wrong position, but now you guessed two other correct letters, u and v. Since there is only one u in the target word, and since neither of the u's that you guessed are in the correct position, your status information should indicate that one u is in the wrong position:

Your next guess is games. While it's true that you know there are no s's in the solution (from your guess of spray earlier), you're trying to see if some of these other letters are present (the g, m and e) and you're still trying to figure out where the a goes. The status message now that you have the g in the right position and the a is still in the wrong position:

Here is run of this sample game:

How many letters should the secret word have? 5
Enter a 5 letter word: spray
Enter a 5 letter word: arrow
Enter a 5 letter word: uvula
Enter a 5 letter word: games
Enter a 5 letter word: curve
Enter a 5 letter word: suave
Enter a 5 letter word: guava
You won in 7 turns!

Helpful tips

Warning: When you get this working, be prepared to spend a while playing as it is remarkably addictive!

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