CompSci 100, Fall 2009
Animal/Twenty-questions Web 2.0 Style

Introduction

For this assignment you'll create a model that allows the user to play a game of twenty questions. The game uses a binary tree to store answers, so you'll get practice reading/writing and manipulating trees. You'll read and write trees and store a root-to-leaf path as the user plays the game.

Snarf the code via Eclipse/Ambient using twentyq, or browse the code directory online. The snarf URL is http://www.cs.duke.edu/courses/cps100/fall09/snarf

Introduction

The video on the left introduces the animal, vegetable or mineral quiz that is related to the game of Twenty Questions. The game illustrates some information-theoretic notions, but it is simply often amusing, especially if the domain of questions is one you find interesting. You can play an AI/hybrid version of the game online at 20q.net.

For this assignment you'll write a program that permits the user to play a dynamic version of twenty questions --- dynamic in the sense that the user can add new questions, save the game, then replay the game with the new questions.

In this assignment all questions have "yes/no" answers, more sophisticated options aren't part of the game.

You can see a video of someone playing a final version of the game to see how the GUI works. You're given the GUI for the game and you'll have to complete the model by writing code using binary trees. You can see that other people write such programs by looking at this question via Stackoverflow.

For infomation about an old TV show named 20 Questions see this Wikipedia article and this link for a technical article on playing twenty questions with a liar.

Code You Write

You'll write code in the model to facilitate playing a game of Twenty Questions. You'll need to understand how the view and the model communicate -- the trace of method calls from one to the other is more complex than in previous model-view programs. In particular you must do the following in the model:

  1. Read a file that represents a twenty-question tree. The file is stored in a pre-order format, you read and store the file so the game can be played.

  2. Keep track of state in the model so that as the user responds "yes" or "no" to a series of questions the path from the root to a leaf is stored so that at the end of the game new information can be added to the game/tree.

  3. Keep track of state in the model so that the communication with the view can happen. This will require storing state in instance variables you design so that the game can be played according to the model-view conventions explained in the howto document.

  4. Write a file so that a game can be played using a tree that has been modified during the course of playing a game in which information is added to the tree.

  5. Create a new game and upload it to the class Web 2.0/Twenty Questions site so that everyone in the class can play it.

Playing the Game

The program is run from the main method in the GameMain.java class. Until you complete the model, however, the game won't be complete. When you've completed writing code for the game, it may look like the screenshots in the howto. These screenshots show you how the game will be played. You must read and store a tree before the game is operational. Use the File menu to load a file provided to you, create a new file, or use the "load URL" to visite the class website for many files representing games. When you download the project you get a simple file animal.txt about which you can find more information in the howto pages. You won't be able to use the yes/no buttons or the newgame menu until you call myView.setEnabled(true) from the model, presumabely after you've loaded file. Without such a call the buttons and menu-item will be grayed-out or disabled until then.

Consult the howto pages for a sequence of screen shots and more information on playing the game.

Reading a File

The howto pages provide hints and an explanation of how to read the tree which is stored in a pre-order traversal format.

Adding New Knowledge

The game is dynamic in supporting the addition of new knowledge and the use of this knowledge in subsequent games. The howto pages show a sequence of screen shots with a complete explanation of how your game should support the addition of new knowledge.

The Program You Write

You must write a program that allows the user to play a game of twenty questions as described. The user can add new information to the tree as the game is played. The user should be able to play more than once during a run of the program. The user should be able to save the tree to a file specified by the user. You can do this entire assignment by completing the class AnimalGameModel as described in the howto pages.

Most of the control aspects of the program are already incorporated into the class AnimalGameViewer that is similar to previous view (e.g., Markov) implementations we've seen in other programs. You'll need to implement the AnimalGameModel class so that it works together with the view similarly to the other MVC programs you've worked on this previously. The model is described in the howto pages.

More details on the I/O and pre-order traversals can be found in the howto pages.

What to Submit

This assignment is worth 40 points, the breakdown is as follows:

functionality points
read/save file to play 10
play game/add info to tree 10
style of game and code 10
data file created 5
README 5

For style of game and code, the user should see the path of the game, e.g., yes/no when deciding on new knowledge -- that's part of style of game. For style of code, be sure to include your name in the comments, be sure to write readable code, and so on.

You must also submit a README file in which you list all the people with whom you collaborated, and the TAs/UTAs you consulted with. You should include an estimated of how long you spent on the program and what your thoughts are about the assignment.

You must create a sample data file whose name indicates something about its contents. The questions should be yes/no questions about any topic, e.g., animals, elements from the periodic table, courses at Duke, and so on.

You should upload the file you create using the this web page which is netid-authenticated and which generates a file read by the view to allow all game-files to be shared among the class.

Submit via eclipse using twentyq.