// Name: PlayOneRound() // Params: a BinSearchTree object // Returns: none // Purpose: plays one round of 20Qs by asking if the person the user is thinking of has a specific characteristic, // then tries to guess the person after narrowing down the characteristics using LearnsNew() public void PlayOneRound(BinSearchTree bst) { // start at the root Node temp = bst.Root; // while we're not at a leaf node while (temp.YesPtr != null && temp.NoPtr != null) { // ask the node's question and get the answer Console.Write("Is this person " + temp.Question + "? "); answer = Console.ReadLine(); // based on the answer, follow either Y/N pointer if (answer.ToUpper() == "Y") { temp = temp.YesPtr; } else { temp = temp.NoPtr; } } // program tries to guess the person Console.Write("Is it " + temp.Question + "? "); answer = Console.ReadLine(); // if the guess is correct, the program wins if (answer.ToUpper() == "Y") { Console.WriteLine("Hurray! I win!"); } // else the program asks who it was and how to tell the difference else { LearnNew(temp); } }