597 Assignment 5: The Animals! Game
Fall 2006, David Matuszek
Animals! is an old computer game, originally text only. The user thinks of an animal, and the computer asks a series of yes-no questions, ending with guessing the animal. If the computer guesses wrong, the computer asks the user about that animal, so that it can guess better next time.
Your assignment is to design the XML representation of the data, use the DOM parser to read it in, play the game, modify the DOM tree to include any new animals the user provides, and write the modified (larger) DOM tree out again when the user quits the game.
The program starts with a very simple decision tree, such as this one.
After asking the user to think of an animal, play may go something like
At this point the computer has "lost." It then asks the user for information that it can use to enlarge its decision tree, like this:
The computer can now replace its wrong answer ("horse") with a new node containing a question, with its wrong answer as one child and the new animal as the other child.
I will provide you with a version of this game that uses a GUI and keeps its data in a binary tree. It can do all of the above, but when the program quits, it forgets everything that it has "learned." You can use this program as a basis (discarding the binary tree part), or you can write your own program from scratch.
First, design the XML you will want to hold the "Animals" data. It can be fairly simple--you don't need to use more than the very basic features of XML.
Write a DTD that describes your XML file.
Write a program that:
These files are fully commented, but I did not include the Javadoc files. You can easily generate them if you wish.