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.
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:
showModalMessage which pops up a dialog box the user
must take action with -- e.g., when the game is over.
messageViews to show an informational message in
the view, e.g., the number of guesses left. This is shown in the textbox
in the lower part of the GUI/view in the screen shots above.
doGuess which sends a String to
the view, i.e., the computer's guess.
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:
myView.processGuess(guess) to show the user the
word the computer/model is guessing -- this is
done by calling the model's private doGuess method.
process method which calls
processResponse (assuming
state set appropriately above) with the number of letters in common with
the last guess. If this number is six, the game is over. Otherwise, the
model calls doGuess with a guess unless
there are no more guesses left. This step repeats.
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.
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.