spec7 - CSE 143, Winter 2010 Programming Assignment #7:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 143, Winter 2010 Programming Assignment #7: Twenty Questions (20 points) Due Thursday, March 4, 2010, 11:30 PM This program focuses on binary trees and recursion. Turn in files QuestionTree.java and QuestionNode.java from the Homework section of the web site. You will need support files UserInterface.java , QuestionMain.java , VaderMain.java , and input text files from the Homework web page; place them in the same folder as your class. The Game of 20 Questions: In this assignment you will implement a yes/no guessing game called "20 Questions." Each round of the game begins by you (the human player) thinking of an object. The computer will try to guess your object by asking you a series of yes or no questions. Eventually the computer will have asked enough questions that it thinks it knows what object you are thinking of. It will make a guess about what your object is. If this guess is correct, the computer wins; if not, you win. The computer keeps track of a binary tree whose nodes represent questions and answers. (Every node's data is a string representing the text of the question or answer.) A "question" node contains a left "yes" subtree and a right "no" subtree. An "answer" node is a leaf. The idea is that this tree can be traversed to ask the human player a series of questions. For example, in the tree below, the computer would begin the game by asking the player, "Is it an animal?" If the player says "yes," the computer goes left to the "yes" subtree and then asks the user, "Can it fly?" If the user had instead said "no," the computer would go right to the "no" subtree and then ask the user, "Does it have wheels?" This pattern continues until the game reaches a leaf "answer" node. Upon reaching an answer node, the computer asks whether that answer is the correct answer. If so, the computer wins. The following partial output log shows one game being played on the above tree: Is it an animal? yes Can it fly? no Does it have a tail? yes Would your object happen to be mouse? yes I win! Initially the computer is not very intelligent, but it grows more intelligent each time it loses a game. If the computer's answer guess is incorrect, you must give it a new question it can ask to help it in future games. For example, suppose in the preceding log that the player was not thinking of a mouse, but of a cat. The game log might look like this: Is it an animal? yes Can it fly? no Does it have a tail? yes Would your object happen to be mouse? no I lose. What is your object? cat Type a yes/no question to distinguish your item from mouse: Does it meow? And what is the answer for your object? yes Is it an animal? Can it fly? bird Does it have a tail? mouse spider Does it have wheels? bicycle
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

spec7 - CSE 143, Winter 2010 Programming Assignment #7:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online