Compsci 100, Fall 2006, Jotto

The Rules of Jotto although we won't be using the scoring system they describe.

Heres's a simple web-based version of game although the version you write will be much better and you'll be able to share it with friends.

Check out the Compsci100/Jotto assignment. The starting code is accessible in the code directory or snarf it via the site.

See javadoc for classes provided.

You'll be programming the model in an MVC architecture for a game of Jotto in which you can play in two modes: you guess the computer's secret word or the computer guesses your secret word.

In this write-up there is first a description and screen shots of how the game is played. Then the code you write is described after the game description and screen shots.

You Guess the Computer's Secret Word

In this mode you get 15, 12, or 10 guesses to guess the computer's secret word when a new game starts. You'll need to write code for a class JottoModel that allows the user to play a game in this way. The code is described after the screen shots and game description.

On the right there's a screen shot of the end of a medium game (user gets 12 guesses) in which I'm trying to guess the computer's word. After I've guessed pails I can determine that the following letters are not in the secret word from the words with zero letters in common with the computer's secret word.
   a e i l p r s t y
Since fruit has two in common, these must be the letters
   u f
Since spoil has one in common, that letter must be 'o' (given the letters not in the word). From ghost we know one of 'g' or 'h', but not both, is in the secret word. After guessing stage we know the letter must be 'g'. So we now know these letters are in the secret word:
   f g o u
and after guessing goofy we can determine these letters are not in the secret word.
   a b c d e h i l m p r s t y
At this point I guessed fungo which is a kind of baseball bat used in batting practice.

After guessing the computer responded that there were five letters in common and that I won the game as shown on the left below.

I don't always win. On the right is a screen shot of an easy game (I got 15 guesses) in which I figured out the five letters on guess number 12 with slate, then guessed three more words with the same letters only to lose.


Computer Guesses Your Word

Here's a screen shot of me choosing to let the computer guess my secret word by choosing the New Game menu and the appropriate option. (The code section below tells what happens in the model code you write when this choice is made.)

When the computer guesses your word, the code you write will not mimic what a human does. For extra credit you can use some human-like reasoning, but as you'll see a simple method allows the computer to guess most words very quickly.

The main idea is for the computer to guess a word that could be the secret word, choosing one such word at random. When the user responds with the number of letters in common with the user's secret word, the computer eliminates every word in its dictionary that doesn't have this many letters in common.

For example, if the computer guesses fruit and the user responds that there are two letters in common with the user's secret word, the computer can remove ghost, ruins, tires and lots of other words from the dictionary since these words have, respectively, one, three, and three letters in common with fruit and thus cannot be the secret word. The computer would leave flips, track, and others in the dictionary since these have two letters in common with fruit and could possibly be the user's secret word.

The computer continues to guess a word that could be the secret word until either the computer guesses correctly or there are no words left to guess. The latter could happen, for example, if the user's word is not in the computer's dictionary or if the user makes a mistake in responding about the number of letters in common (see below for examples).

The computer generates a guess and I type in the number of letters in common with my secret word which is radii in the examples that follow. The computer has guessed my word in nine guesses and I type the number 6 to indicate this is my secret word (as shown on the right). This is an easy way to convey "you guessed right" to the computer which in general expects a number from the user in this version of the game.


Here are two more shots of the computer guessing my word radii. As these show, the computer doesn't use the same sequence of guesses every time, and sometime guesses the word very quickly!


Finally, two more shots of the computer trying to guess radii. On the left it seems like a sequence of very strange guesses leading to the secret word. On the right I made a mistake and entered 3 for the word drain which has four letters in common. The computer can't account for this mistake and indicates no more guesses after six guesses.


Code You Write

You're given Jotto the main class that launches the GUI, the JottoViewer GUI class and an AbstractJottoModel abstract class you will subclass to create the model that 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 GUI allows this).

The code has been designed so that you can create a subclass of AbstractJottoModel, implementing the three methods described in comments of that class and designing state appropriately for the model to either guess the human-user's word or for the human-user to guess the model's secret word.

You may find it useful to write helper methods in the class you write, that are called by the three methods you must write --- these three methods are abstract in the base class.

You must call your class JottoModel to make the main program Jotto work with your code.

The screen shots above show how the game should work. You're welcome to embellish the game --- if you do be sure to document what you did in your README.

See the Jotto FAQ for questions and more details.

Model/View Communication

The view calls the model by sending an Object, typically a String, to the model's process method. Since you're writing JottoModel as a subclass of AbstractJottoModel, you should be able to ignore process (relying on its implementation in AbstractJottoModel) and only write processHumanCount(..) and processHumanGuess(..) which will change state in your model and call appropriate methods in the view. These methods are called, respectively, when processing the number of letters in common when the computer is guessing the user's secret word (processHumanCount) and when the user is guessing the computer's secret word (processHumanGuess).

The model communicates with the view by calling:

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 processModelResponse. 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 processHumanCount), and so on. Thus model-view communication is started by the model in this scenario and works like this:

When newGame is called when the user is guessing the computer's word, the first communication between the model and the view will be generated by the view -- the model gets the user's guess and sends the number of letters in common back to the view via processModelResponse.

The scenario works like this.


This assignment is worth 30 points.

Criteria Points
Human-user can guess computer's secret word (generally). 6
Computer will guess users's secret word (generally). 6
Everything works well 8
Documentation, style of code 6

In your README, which you must submit, you should include

For extra credit you can allow the user to give up and find the computer's secret word (e.g., add a new menu option for this).

For other extra credit, use your imagination and document it.

Submit using jotto via Eclipse.

Owen L. Astrachan
Last modified: Thu Aug 31 14:18:01 EDT 2006