Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Palm Programming for the Absolute Beginner

Palm Programming for the Absolute Beginner

Discuss PocketC for Palm OS (including Desktop Edition)

Postby winhax on Wed May 17, 2006 6:20 am

Hi all,
I hope someone can shed some light on my possible dilemma. At the end of chapter 4 of the <u>Palm Programming for the Absolute Beginner</u> book, The last two challenges are for making the classic "I am thinking of a number" game. Now I had no problems creating it from the programs perspective. What I'm having trouble with is creating it from the user's view. In other words, the user thinks of a number between 1 and 100 and then the computer "guesses" what it is. Maybe I'm doing too much work at this point but is the computer (PDA) supposed to know and remember what guesses it made or is it supposed to just keep guessing until it guesses correctly? I can't seem to get a simple algorithim for storing values that it already guessed and also not to guess a lower (high) value than it's last guess. I'd really appreciate anyones' help on this because I can't figure it out for the life of me.

Thanks,

J
winhax
 
Posts: 2
Joined: Wed May 17, 2006 6:01 am
Location: USA

Postby mgreen on Wed May 17, 2006 11:29 am

You could do it either way (remember past guesses or not). There are lots of ways for the program to remember a series of values. What have you learned so far from the book along these lines? In terms of the computer guessing ... You can use a "pseudo-random" number generator or you can use the user interaction. If the user has to tap the screen to get the computer to provide a number, the amount of time waiting for the user can be a nearly random number, particularly if you use the remainder from a division by 100. You can also multiply the time by a moderately large prime number, then take the remainder
-----
Michael Green
mgreen
 
Posts: 72
Joined: Fri Mar 14, 2003 9:40 pm
Location: USA

Postby winhax on Wed May 17, 2006 6:03 pm

OK here is what I have so far...

<b><font color="blue">//iatoanu
/*
Classic I am thinking of a number game
Jason Puehler, 05/13/06
*/

@cid "User";
@name "UserG";
@dbname "RandomG";
@ver "0.1";
@category "Games";

//main variables
string Fname;
int PalmG;
int PalmH;
int PalmL;
string UserA;

gn() {
//start gn()
UserA = gets("Correct(C)/Higher(H)/Lower(L)?");
UserA = strupr(UserA);
if (UserA == "C") {
alert("I knew it!");
} else if (UserA == "H") {
PalmH = 100 - random(PalmG) > PalmG;
clear();
puts(PalmH);
return gn();
} else if (UserA == "L") {
PalmL = random(PalmG) + 1 < PalmG;
clear();
puts(PalmL);
return gn();
} else {
alert("Incorrect Entry, Please try again.");
return gn();
} //end if
} //end gn

splash() {
//start splash() function
clear();
title("I am Thinking of a number...");
puts(" Hi, Welcome to my game.");
puts("\n\n");
puts(" Think of a number between 1 and 100.");
puts(" I bet my program can guess your number");
puts("\n\n");
puts(" Tap the screen to continue...");
wait();
clear();
Fname = getsd("What's your first name?","Jason");
}//end splash

main() {
splash();
PalmG = random(100) + 1;
clear();
puts(PalmG);
gn();
clear();
exit();
} //end main</font id="blue"></b>
winhax
 
Posts: 2
Joined: Wed May 17, 2006 6:01 am
Location: USA

Postby sangahm on Wed May 17, 2006 6:27 pm

Your way of having the PDA guess the number is very inefficient. If you want to go that way, you may want to create an array of past guesses so that a guess is not repeated.

Otherwise, think about a binary approach where the PDA guesses by dividing the field of guesses in half each time. This would be most efficient.

In other words, if the field of possibilities starts at 0 to 100 and the number is "x", the first guess would be 50 (half of the field). The next guess would be either 50 to 100, or 0 to 50 depending on if the guess was high or low. If the guess was low, then you know the answer is between 50 to 100, so the guess would be 75. If the guess was high, then the guess would be between 0 to 50, so the guess would be 25. One thing to think about is after the first guess, the "new max" or high boundary to guess keeps changing after each guess. (In the above example, the new max would be either 50 or 100 depending on whether the guess was high or low). Keep that guess going until you home in on the answer.

You can add the variability I think you are looking for by making the next guess be a random number *between* the last guess and the new_max.

That way the only things that you would have to keep track of was the current_guess, next_guess, new_max and result_of_guess (correct, higher, lower).

The function would keep looping until the correct answer was guessed.

Now all you have to do is put the above into code. ;)
sangahm
 
Posts: 118
Joined: Mon Jul 04, 2005 3:43 pm
Location: USA


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 3 guests

cron