It has been years since I have actually tried to write any kind of somewhat complex program, and now that I'm back in school I;m finding those to be kind of frustrating.
I have been assigned to write a guessing and learning program using a custom binary tree. The root of the tree is the very first guess. If the guess is incorrect, the program prompts the user to enter the correct thing and a yes/no question to ques between the two. Then it rotates the nodes so that the question is first, the yes branch has the correct answer, and the no branch originally is the wrong guess, but after the next cycle becomes the new quesing question. Hope that made sense. After it has this new information, it asks if the user wants to start over. If they do, it begins from the top, but this time the root is the first distinuserInterfacesing question.
The way we have to set it up, we have a DTNode class, that then has two subclasses, TNode and QNode.
Example run (with original root of TNode("Tiger"):
Game asks: Is it a tiger?
User enters: no.
Game asks: What were you thinking of?
User enters: lion
Game asks: Please enter a yes/no question to ques between a tiger and a lion
User enters: does it have a mane?
Game asks: Would you like to play again?
User says: yes
Game asks: Does it have a mane?
User says: yes
Game asks: is it a lion?
and so on. Hopefully that is clear enough.
I have the Node classes all written and working, but my problem is in the implementation of the tree.
I was trying to write a runner program to run a sample of the game and this is what I came up with so far. I am totally lost on where to go from here.
[source lang="java"]import java.util.*;public class Tree{public static void main(String[] args){USERINTERFACE userInterface = new USERINTERFACE();TNode root = new TNode("Tiger");do{traverse(root);}while (userInterface.confirmation("Would you like to play again?"));userInterface.outputInfo("Thank you for playing and helping me learn!");}public static void traverse(DTNode current){if (userInterface.confirmation("Is it a " + current.getString() + "?")){userInterface.outputInfo("I guessed it!");}else{String thing = userInterface.promptUser("I give up!\nWhat kind of animal were you thinking of?");TNode tNode = new TNode(thing);String ques = userInterface.promptUser("Please enter a yes/no question that ques between a " + current.getString() + " and a " + tNode.getThing());QNode qNode = new QNode(ques, current, tNode);current = qNode;}}}[/source]
I have stared at it for hours and tried many things, and cannot for the life of me figure out where to go from here. I have spoken with my professor, and he has not helped much.
Any advice would be greatly appreciated. I am on a time crunch, and helpful posts will be rated as such.
Thank you mighty programmers of gamedev.net
Edited by Alatar, 05 November 2012 - 12:12 PM.






