Question: Submit twenty.c , bst . c and bst . h to Gradescope. Twenty Questions Twenty questions is a parlor game in which one person thinks
Submit twenty.c bstc and bsth to Gradescope.
Twenty Questions
Twenty questions is a parlor game in which one person thinks of something and the others need to guess what it is by asking questions that can be answered with a 'yes' or a no It became popular in the United States in the th and th centuries and became a popular radio and television game show. It encourages deductive reasoning and actually has applications in computer science and information theory. There is even a video game called Akinator which attempts to determine what fictional or reallife character, object, or animal a player is thinking of by asking a series of questions. It uses artificial intelligence to learn the best questions to ask the user via its experience.
Requirements for Twenty Questions about Fruits and Vegetables
A program is needed to allow a person to play a guessing game with the computer. The user thinks of a fruit or vegetable and the computer asks questions that the user answers with a y es or a n o The user wins if the computer cannot correctly guess the fruitvegetable
Bonus: If the computer loses, it prompts the user to enter a question that it could have asked to improve its chances of guessing correctly. It stores this question such that it can ask it in the future when it reaches this point in a game. In this way it can improve its performance. You don't need to implement this, but if you do it successfully then you will have the satisfaction of having done it successfully.
Design
A binary tree should be used to store the questions that the computer will ask. The leaf nodes should contain the names of fruits and vegetables while the inner nodes contain the questions. You should build the tree before the game starts. An example is shown below. You can reuse the code for the simple guessing game that we created for previous assignments. No file IO or leaderboard functionality is required. Implementation
The program will be written in C Try to write your program incrementally by first creating the overall structure with empty functions stubs and testing often to see that your program is always working as expected. Use the code from our slides for the BST that uses recursion.
Testing
When testing, you are checking to see that the program satisfies the requirements.
Remember that when moving through the stages of requirements, design, implementation and testing, it is often necessary to go back to a previous stage and revisit decisions and make changes. It is always better to make design changes early in a project rather than later. Example tree:
struct node creategametree
struct node root NULL;
root insertroot "Does it grow underground?", ;
insertrootIs it long in shape?", ;
insertrootIs it orange in color?", ;
insertroot "It's a carrot!";
insertroot "It's a parsnip!";
insertrootIs it red in color?", ;
insertroot "It's a radish!";
insertroot "It's a potato!";
insertroot "Does it grow on a tree?", ;
insertrootIs it red in color?", ;
insertroot "It's an apple!";
insertroot "It's a peach!";
insertrootIs it red in color?", ;
insertroot "It's a tomato!";
insertroot "It's a pea!";
return root;
int main
struct node gametree creategametree;
printfWelcome Press q to quit or any other key to continue:
;
char c gameover ;
Also, the node was defined in bsth as:
struct node
int data;
char question;
char guess;
struct node left;
struct node right;
;
That way the BST property can be used to order the nodes properly. Also, either the question or the guess will be an empty string so the program will know which to print for the user. Example run:
Welcome! Press q to quit or any other key to continue:
x
You think of a fruit or vegetable and I will try to guess it
Does it grow underground?
mathrmymathrmn : y
Is it long in shape?
mathrmymathrmn : n
Is it red in color?
y n : y
It's a radish!
y n: y
I win!
Press q to quit or any other key to continue:
x
You think of a fruit or vegetable and I will try to guess it
Does it grow underground?
y n : n
Does it grow on a tree?
mathrmymathrmn : y
Is it red in color?
yn: y
It's an apple!
mathrmymathrmn : n
You win!
Press q to quit or any other key to continue:
q
Bye Bye!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
