Compsci 100, Fall 2011, Jotto How-to

You can browse the code we provide and you can snarf it using our Ambient/Eclipse plugin --- check out the instructions on how to download the ambient system and how to use it to check out a project.

The snarf url for this CompiSci 100 is http://www.cs.duke.edu/courses/cps100/fall11/snarf/.

You're given Jotto the main class that launches the GUI, the JottoViewer GUI class and a JottoModel class with TODO/methods marked that you must implement so the model plays a game and communicates with the view/GUI.

You're also given a file of five-letter words though you're free to use your own file (the Jotto/main method allows this).

The code has been designed so that you can implement a few, marked (TODO) methods in JottoModel, implementing the methods described in comments of that class and designing state appropriately for the model to guess the human-user's word.

You may find it useful to write helper methods in the class you write.

Load the file kwords5.txt from the GUI/File menu before starting to play.

Model/View Communication

The view calls the model by sending an Object, typically a String, to the model's process method. You're given code in JottoModel so that process calls the method processResponse you must write, you should be able to ignore the method process (relying on its implementation).

The model communicates with the view by calling a private, helper method:

For example, when the computer is guessing the user's word, the model's newGame method will be called -- you write this code. You must start the model-view-model-view... communication by sending a guess to the view via doGuess. The view will then send the number of letters in common back to the model. The model must then make a guess and send the guess to the view which will send back a number of letters in common (by calling process which calls processResponse), and so on. Thus model-view communication is started by the model in this scenario and works like this:

Two Common Errors

Here are two common mistakes:

Forgetting to remove the currently guessed word from the list, when the user selects "5". It might initially seem like if the user selects 5 the game ought to be over. But that's not true: I could guess "bagel" and all 5 letters are correct, but the actual word is "gable". Order matters in Jotto.

One common problem students have is when the guess "bagel" and 5 is the result, "bagel" is not eliminated from the list of words, so the AI will stupidly guess "bagel" again. So be sure to eliminate the guessed word from this list of new possible words.

Modifying the word list so that your can't play a second time. So when the user loads a data file, the word list in JottoModel gets filled with all the words. It's important that when you eliminate words, you somehow keep a backup of the original word list. If you don't and modify the original list directly - eliminated words will be removed from the game forever. Then when the user selects "new game" again, the computer won't know those words to guess.

Extra Credit

For the extra credit portion of the assignment, you'll want to make the AI implement a smarter strategy than described in the assignment and howto. To do this - don't focus on the elimination of words...what you have built is actually a pretty good strategy for discovering what words are impossible. Instead - think about how you select a word out of the possible words to be the next guess. Right now, the strategy just selects a random word from all the possible words. Rather than selecting a random word maybe it would be better to select a word that either will give a lot of new information about what letters are in the real word.

The way play smarter is intended to work is that before the game, the user goes to the menu and selects the "Smart" option. This should "turn on" smart mode (use it to set an instance variable in your object). From then on, the AI should act using your better smart algorithm.