• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Guessing Game

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me come up with the classes and methods needed for this program. I can write them myself. I just need some ideas for the design and some test plans. All of which I can write on my own. I am just asking for some suggestions on how you all at the ranch would tackle this problem as experienced programmers.

I need to write a program that can learn about players in a particular sport. The program will play a game in which the user thinks of a player, and the program tries to guess the player. When it fails to guess the player, the program solicits information from the user that will help it do better next time. For example, here is a sample transcript of the program in action (computer output in black, user input in red italics):

Pick a sport: basketball
I don't know anything about basketball. Please teach me.
Who is your favorite player? Magic Johnson

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is it Magic Johnson? No
I give up. Who is it? Michael Jordan
Please enter a question whose answer is yes for Michael Jordan
and no for Magic Johnson:
Is he known for sticking his tongue out?

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? No
Is it Magic Johnson? No
I give up. Who is it? Mugsy Bogues
Please enter a question whose answer is yes for Mugsy Bogues
and no for Magic Johnson:
Is he shorter than 6 feet?

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? No
Is he shorter than 6 feet? Yes
Is it Mugsy Bogues? Yes
I win!

Ok, think of a player and I will try to guess who it is. Ready? No

Good-bye. Pick basketball next time to continue game.

Between sessions, the program will save the information it knows in a file named game.txt, where game is the name entered by the user. (In this case, the file would be basketball.txt.) If the user picks the same game later, the program will re-load what it already knows about that game. For example, the next session might proceed

Pick a sport: basketball

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? Uh-huh
I'm sorry. I didn't understand that answer. Let's try again.
Is he known for sticking his tongue out? Yes
Is it Michael Jordan? Yes
I win!

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? No
Is he shorter than 6 feet? Yes
Is it Mugsy Bogues? No
I give up. Who is it? Spud Webb
Please enter a question whose answer is yes for Spud Webb
and no for Mugsy Bogues:
Did he win the Slam Dunk contest?

Ok, think of a player and I will try to guess who it is. Ready? No

Good-bye. Pick basketball next time to continue game.

Thanks for your help!
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as always, you start by NOT thinking about java, or classes, or data structures, or methods. You start by writing down in english what needs to be done. You then refine it and clarify. Eventually, you get to the point where you start realizing what sorts of classes/methods you need.

I would start by writing down something like

"I need to keep track of players in different sports. So I need a bunch of basketball players, a bunch of baseball players, etc. I won't know what all sports may be included, so I need to be able to add new ones on-the fly. I will need to keep track of questions that identify each player. Can a single question apply to more than one person? Do I need to be able to pick the question that eliminates the most people? When the user exits, I need to save all the new data - could be in a text file, could be in a database."

So now I realize that (for this), there is no difference between a basketball player and a Darts player. I have a person, I associate a sport with them, and I maintain a list of questions for each player. And I continue on like that.

I would probably spend a day or two thinking about it, running through various scenarios in my head, and writing them all down.

Once I got to the point of coding, I would write VERY small pieces at a time. I never write more than 2-3 lines before I re-compile.
 
William Koch
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Fred! I appreciate your feedback. I will give it a shot and post back in a few days!
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic