Animal Game


TITLE
Animal Game

DESCRIPTION
You are to write a program that determines what animal the user is thinking of by analyzing the responses to a set of yes/no questions. The program can learn to classify new animals by asking for help from the user when it makes a mistake.

You have considerable flexibility in the exact look of the program, but it should have functionality comparable to that shown in the following example.

EXAMPLE
Here is an example run of the program. User input is shown in bold.
$ python animal.py
Welcome to the Animal Game!
You pick an animal, and I will try to guess what it is.
You can help me get better at the game by giving me more
information when I make a mistake.

The more you play, the better I get.

Think of an animal, and I'll try to guess what it is.
Is it green? no
Does it purr? n
Does it have black and white stripes? y
Does it have hooves? yes
Is your animal a(n) zebra? yes
I'm soooo smart!

Do you want to play again? y
Think of an animal, and I'll try to guess what it is
Is it green? yes
Does it hop? yes
Is your animal a(n) frog? no
Rats! I didn't get it. Please help me improve.

What is your animal? grasshopper
Please enter a yes/no question that would select
between a(n) grasshopper and a(n) frog:
>> Does it eat leaves
What would the answer be for a(n) grasshopper? yes

Do you want to play again? yes
Think of an animal, and I'll try to guess what it is
Is it green? y
Does it hop? y
Does it eat leaves? y
Is your animal a(n) grasshopper? yes
I'm soooo smart!

Do you want to play again? n


Thanks for playing!

HINTS
In this program, you will make use of the binary tree data structure. You will need to implement the BinaryTreeNode and DTree (decision tree) classes that we discuss in class. The exact design of these two classes is up to you, but you should ensure that the DTree completely hides the details of the implementation (i.e. no (public) method has a parameter or return type of BinaryTreeNode).

You will have to save your decision tree to a file to save the data between runs of the program. The simplest way to do this is to "serialize" the DTree object. In Python, this is done using the pickle module. Look at the documentation for pickle.dump and pickle.load to see how this is done.

When started, your program should try to load the current information from the file "animal.db". If this file does not exist or the contents are unreadable, the program should print a warning that no existing database is available and start a new decision tree "from scratch". That means creating a tree with a single node for some default animal, such as "dog". The final tree should be saved back to animal.db when the program quits. Note, this means you can always "rebuild" the game by simply deleting (or renaming) the database file.

You will hand in both your source code and an example animal.db file. Your source code should be fully documented, including pre and post conditions for each method of DTree.

Groups are OK. Four is the maximum number of bodies in a group, unless you have prior permission from me.

Have fun!