Game question. help me

This is a discussion on Game question. help me within the C++ Programming forums, part of the General Programming Boards category; an integer number between 0 and 99. With just 6 question. to guess correctly!!! 6 Question of me. ( numbers ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    20

    Game question. help me

    an integer number between 0 and 99. With just 6 question. to guess correctly!!!
    6 Question of me. ( numbers is 13 )
    Computer: Is your number bigger than 50?
    User: No
    Computer: Is your number bigger than 25?
    User: No
    Computer: Is your number bigger than 12?
    User: Yes
    Computer: Is your number bigger than 18?
    User: No
    Computer: Is your number bigger than 15?
    User: No
    Computer: Is your number bigger than 13?
    User: No
    Computer: your number is 13, right?
    User: Absolutely right. Exactly right. You are genius computer.
    Error: numbers 14??
    Who can do other algorithms??? Help me!!!

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    where is it you are having trouble with this? maybe you could try a flow scheme to start with then try and put it into code

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    20
    put it in the code but then fails when put six questions

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    do you mean this is your sample output? or this is your algorithm or what you want to happen? have you any of your code to post?

    Computer: Is your number bigger than 50?
    User: No
    Computer: Is your number bigger than 25?
    User: No
    Computer: Is your number bigger than 12?
    User: Yes
    Computer: Is your number bigger than 18?
    User: No
    Computer: Is your number bigger than 15?
    User: No
    Computer: Is your number bigger than 13?
    User: No
    Computer: your number is 13, right?
    User: Absolutely right. Exactly right. You are genius computer.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    20
    Okie. thanks you! I want to just six questions to guess the number between 0-99 you think. I think this is a very interesting problem. I asked six questions above so, but guess not

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    so.....
    have you any of your code to post?

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    20
    can you code help me?? because algorithm of me fail, thanks you very much.

  8. #8
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    if you are capable of stepping through your algorithm on paper (as you say you have no code)
    can you code help me?? because algorithm of me fail
    and find that something is wrong with it, then surely you are also able to say what your error is, what you guess it is, or at least show us what your working out is
    Last edited by rogster001; 10-29-2009 at 08:08 AM.

  9. #9
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    The program needs to keep a lower limit a and an upper limit b for the number x, so that a <= x <= b. From the beginning a = 0 and b = 99. The program then makes up a number c between a and b (it has to be lower than b), maybe c = (a+b)/2, and asks the user if x is bigger or not. If it is bigger, it sets a = c+1, else it sets b=c. You repeat the process untill a and b are equal.
    Come on, you can do it! b( ~_')

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    The number of questions that need to be asked is floor(log2(N)) where N is the range of possibilities. The algorithm the program is using is bisection. It keeps track of the low and high points, and asks you about the middle. If the middle is too low, it sets that as its new low point. Vice versa, if the middle is too high, it sets that as its new high point.

    Imagine how you would look up somebody's name in a phone book. You flip back and forth based on your knowledge of the order of the alphabet -- you don't search randomly, or by flipping each page one by one.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  2. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  3. Question on making game.
    By derrick45123 in forum C++ Programming
    Replies: 10
    Last Post: 06-19-2005, 05:12 PM
  4. Question on sound in a game of mine
    By Vanished in forum Game Programming
    Replies: 2
    Last Post: 12-09-2002, 12:56 PM
  5. Question about a game
    By TheGr8one in forum Game Programming
    Replies: 1
    Last Post: 09-15-2001, 10:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21