Author Topic: Hi Lo without Secret Number?  (Read 3592 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #15 on: October 11, 2020, 08:38:49 pm »
Steve, jack you've got it backwards the program is not trying to guess the user's number. The user is trying to narrow down what the program has made up (though the challenge is to not make up any secret number).

OK time to translate the example I worked my Hi Lo Game version from.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #16 on: October 11, 2020, 08:47:48 pm »
I made my version of Hi Lo Game after playing around with this:
Code: QB64: [Select]
  1.  
  2. 'ref tsh73 from JB forum 2020-10-08
  3. 'https://justbasiccom.proboards.com/thread/567/guess-number-secret
  4. 'translated to QB64 b+ 2020-10-11
  5.  
  6.  
  7. 'guessANumber
  8. '   idea
  9. '   instead of making a number
  10. '   we deside on each turn
  11. 'of cource we should store numbers tried to say "no" again
  12. 'and fix probability according to not tried numbers
  13.  
  14. 'logic: loop
  15. '   get a number
  16. '   check if number is new
  17. '       if it is,
  18. '       with probabilty 1/#(numbers left) say Yes and stop
  19. '       (or else)  store it
  20. '       else say No
  21.  
  22. PRINT "---- Guess a number ----"
  23. PRINT "I made up a number, (1..9)"
  24. PRINT "- you guess it. That's all ;)"
  25. PRINT "No! Not quite."
  26. PRINT "Actually I do not made a number."
  27. PRINT "I will deside on the go."
  28.  
  29. tried$ = ""
  30.  
  31.     INPUT "Make your guess (1..9): "; guess
  32.     IF guess < 1 OR guess > 9 OR INT(guess) <> guess THEN
  33.         PRINT "Guess not valid"
  34.         GOTO cont
  35.     END IF
  36.     IF INSTR(tried$, _TRIM$(STR$(guess))) THEN
  37.         PRINT "Already tried that"
  38.         GOTO cont
  39.     END IF
  40.     numsLeft = 9 - LEN(tried$)
  41.     'print "1/";numsLeft,  'and the probability is
  42.     IF RND < 1 / numsLeft THEN
  43.         PRINT "You did it!"
  44.         EXIT WHILE
  45.     END IF
  46.     'else
  47.     tried$ = tried$ + _TRIM$(STR$(guess))
  48.     PRINT "Nope, try again"
  49.     cont:
  50. PRINT "-=* thanks for playing *=-"
  51.  
  52.  

BTW tsh73 is generous programming teacher in Russia, so maybe we can forgive his mistakes of English spelling and grammar.
« Last Edit: October 12, 2020, 11:10:16 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #17 on: October 11, 2020, 08:57:23 pm »
As a joke, I posted this for reply to tsh73:

Code: QB64: [Select]
  1. _TITLE "Guess the cruel joke." ' b+ 2020-10-08 reply to tsh73 trans to QB64
  2.     INPUT "Make your guess (1..9): "; guess
  3.     IF guess < 1 OR guess > 9 OR INT(guess) <> guess THEN
  4.         PRINT "Guess not valid"
  5.         GOTO cont
  6.     END IF
  7.     IF INSTR(tried$, _TRIM$(STR$(guess))) THEN
  8.         PRINT "Already tried that"
  9.         GOTO cont
  10.     END IF
  11.     IF LEN(tried$) >= 8 THEN
  12.         PRINT "You did it!"
  13.         EXIT WHILE
  14.     END IF
  15.     'else
  16.     tried$ = tried$ + _TRIM$(STR$(guess))
  17.     PRINT "Nope, but you're getting closer!"
  18.     cont:
  19. PRINT "-=* thanks for playing *=-"
  20.  
  21.  

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Hi Lo without Secret Number?
« Reply #18 on: October 11, 2020, 09:20:09 pm »
waaait, the backwards version is interesting...

You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #19 on: October 11, 2020, 09:30:07 pm »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #20 on: October 12, 2020, 11:04:54 am »
Here is a distribution of "Secret Numbers" finally determined at games end in 10,000 trials:
Code: [Select]
Secret Numbers results:
Program errors = 0
1             92
2             94
3             101
4             111
5             110
6             100
7             114
8             104
9             91
10            89
11            82
12            122
13            97
14            97
15            115
16            109
17            96
18            97
19            91
20            103
21            108
22            95
23            104
24            99
25            99
26            108
27            104
28            91
29            102
30            105
31            97
32            81
33            106
34            101
35            107
36            89
37            99
38            88
39            87
40            102
41            100
42            107
43            92
44            81
45            84
46            103
47            100
48            98
49            89
50            95
51            107
52            102
53            105
54            95
55            110
56            92
57            119
58            110
59            106
60            93
61            92
62            84
63            103
64            113
65            94
66            95
67            99
68            92
69            99
70            110
71            91
72            96
73            95
74            87
75            93
76            95
77            111
78            102
79            101
80            111
81            113
82            110
83            115
84            95
85            105
86            106
87            107
88            92
89            93
90            118
91            95
92            106
93            91
94            104
95            106
96            104
97            98
98            97
99            101
100           106
Total 10000
 Lowest count 81 for i = 32
Highest count 122 for i = 12


As you can see no holes and no heavy favorites. This tells me this game plays the same as one in which a secret number is decided before the start of each game or round.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #21 on: October 12, 2020, 11:18:34 am »
BTW here is my QB64 version of the backwards (the program guesses my number) Hi Lo Game from 2019:
Code: QB64: [Select]
  1. '2019-09-14
  2.     Hi = 101: Lo = 0
  3.     DO
  4.         guess = INT((Hi - Lo) / 2) + Lo
  5.         PRINT "AI guesses your number ( 1 to 100) is "; guess
  6.         INPUT "Enter l for low, c for correct, h for high > "; r$
  7.         IF r$ = "l" THEN Lo = guess
  8.         IF r$ = "h" THEN Hi = guess
  9.     LOOP UNTIL r$ = "c"
  10.     PRINT "Yeah, start another..."
  11.  
« Last Edit: October 12, 2020, 11:48:23 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #22 on: October 12, 2020, 11:34:59 am »
And just to round things out, here is my version of the Standard Hi Lo Game written in SB (Shorthand Basic) for my Interpreter built with QB64:
Code: QB64: [Select]
  1. Hi lo game SB.txt b+ 2020-03-07
  2. [
  3.     n r int(rnd * 100) + 1
  4.     n c 0
  5.     [
  6.         ? g Guess my number from 1 to 100, (0 quits)
  7.         i  g >= 1
  8.             n c c + 1
  9.             i  g >  r
  10.                 . Too High!
  11.             e
  12.                 i  g < r
  13.                     . Too Low!
  14.                 e
  15.                     . You guessed in c guesses!
  16.                     .
  17.                     x
  18.                 f
  19.             f
  20.         e
  21.             . You signaled quit, goodbye!
  22.             z
  23.         f
  24.     ]  
  25. ]
  26.  

[ starts a loop
] ends a loop

n sets a number variable the very next item in the line is the variable name and the next stuff is number literal or numeric expression for the variables value. (So here, r is the secret number set at the beginning of the round and c is for count as in counting the number of guesses.)

? starts an INPUT statement, next item is the variable name being set and the rest is the propmt string, notice NO double quotes!

i starts an IF branch decision, the stuff following is the expression to evaluate if evaluates to True then execute the next statement else look for an f (the end of an IF block or an e the ELSE block to execute.

. starts a PRINT statement, notice no double quotes BUT if one of the isolated letters or words is a variable name the variable's value will be substituted in for the name.

x of course is for exit loop, the only way out of [ loop code ]

For comments, just don't start a line with a command like [].nxief, but for your comfort use ' to feel safe it wont be used for anything else.

BTW the indents are optional but each executable line must start with executable command. So line 1 is just  comment.

One of these days I am going to work in strings and SUBs or FUNCTIONs.

« Last Edit: October 12, 2020, 11:45:58 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #23 on: October 12, 2020, 03:57:56 pm »
BTW I found the 256 Cards Trick, program can pick your card out of 256 cards by telling it which line of 4 it's in, do this 4 X's and it will count out your favorite number of cards and your card will be last shown.

https://www.qb64.org/forum/index.php?topic=1865.msg111002#msg111002

But again, this is backwards to the challenge presented in OP.
« Last Edit: October 12, 2020, 03:59:14 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #24 on: October 13, 2020, 12:55:02 pm »
Update: tsh73 says my code looks OK (for Hi Lo Game that does not start with established secret numbers) but might have found something literally funny about frequency distribution of resulting "secret" numbers from pure random guessing.

I was only checking guessing with some intelligence being applied including sliding down my guess by 1 number each time, those were fine but pure random guessing produced a frequency distribution chart that lifted up at both ends like a giant smiling at a joke!

hmm... got to check that out, it may be some artifact from the chart system he is using but like I said I never thought to check pure random guessing.

OK so here is my Hi Lo Game that plays without a secret number for QB64:
Code: QB64: [Select]
  1. _TITLE "Hi Lo Game without Secret Number" 'B+ 2020-10-10 works now
  2. ' trans from JB 2020-10-11 minimal changes
  3. restart:
  4. Hi = 101: Lo = 0 '<<<<  make these higher and lower than what the secret number can be
  5. guesses$ = ""
  6. WHILE Hi - Lo > 1
  7.     INPUT "Guess Number 1 to 100, Enter your guess "; PlayerGuess
  8.     'if PlayerGuess = 0 then goto [restart]  ' GOOD! we split first guess of 50 both ways!
  9.     IF PlayerGuess < 1 OR PlayerGuess > 100 THEN
  10.         PRINT "Your guess is out of range of this game."
  11.         GOTO cont
  12.     END IF
  13.     IF INSTR(guesses$, RIGHT$("000" + STR$(PlayerGuess), 3)) THEN
  14.         PRINT "You've guessed that number already."
  15.         GOTO cont
  16.     END IF
  17.     guesses$ = guesses$ + "," + RIGHT$("000" + STR$(PlayerGuess), 3)
  18.     IF PlayerGuess > Lo AND PlayerGuess < Hi THEN
  19.         r = RND: p = 1 / (Hi - Lo - 1) ' must be inside the Lo and Hi range ie not inclusive boundaries.
  20.         IF r <= p THEN
  21.             PRINT "You Guessed!"
  22.             Guessed = 1
  23.             EXIT WHILE
  24.         ELSE
  25.             IF PlayerGuess = Hi - 1 THEN 'guess must of been too high
  26.                 'PRINT Lo, Hi, "Your guess was too high.", r, p
  27.                 PRINT "Your guess was too high."
  28.                 Hi = PlayerGuess
  29.             ELSE
  30.                 IF PlayerGuess = Lo + 1 THEN
  31.                     'PRINT Lo, Hi, "Your guess was too low.", r, p
  32.                     PRINT "Your guess was too low."
  33.                     Lo = PlayerGuess
  34.                 ELSE 'toss coin if too high or low
  35.                     IF RND < .5 THEN
  36.                         'PRINT Lo, Hi, "Your guess was too low.", r, p
  37.                         PRINT "Your guess was too low."
  38.                         Lo = PlayerGuess
  39.                     ELSE
  40.                         ' PRINT Lo, Hi, "Your guess was too high.", r, p
  41.                         PRINT "Your guess was too high."
  42.                         Hi = PlayerGuess
  43.                     END IF
  44.                 END IF
  45.             END IF
  46.         END IF
  47.     ELSE
  48.         IF PlayerGuess >= Hi THEN PRINT "Your guess was too high." ELSE PRINT "Your guess was too low."
  49.     END IF
  50.     cont:
  51. IF Guessed <> 1 THEN PRINT "Yikes! Programming error, did not find secret number."
  52. PRINT: INPUT "press Enter to go again, any other + Enter to quit "; again$
  53. IF LEN(again$) THEN END ELSE GOTO restart
  54.  

And here is what I was using to check frequency distributions of secret numbers discovered at the end of a game:
Code: QB64: [Select]
  1. _TITLE "Hi Lo Game wo secret Test Distribution" '  B+ 2020-10-10 works now
  2.  
  3. DIM secrets(100) 'check distribution of answers, also checking if we fail to arrive at answer
  4. 'SCREEN _NEWIMAGE(800, 600, 32)
  5. restart:
  6. Hi = 101: Lo = 0 '<<<<  make these higher and lower than what the secret number can be
  7. guesses$ = ""
  8. ALO = 0: AHI = 101
  9. Guessed = 0
  10. WHILE Hi - Lo > 1
  11.     'input "Guess Number 1 to 100, Enter your guess "; PlayerGuess
  12.  
  13.     'use AI to guess
  14.     'PlayerGuess = int((AHI - ALO)/ 2) + ALO 'OK have removed blunder!
  15.  
  16.     'make all the guesses way too high ie ride the AHI down 1 by 1
  17.     PlayerGuess = AHI - 1 'Ah still a very nice ditribution of secrets, no holes nor mountains
  18.  
  19.     'PlayerGuess = int((Hi - Lo )/ 2) + Lo  'debug what the heck is going on with ALO AHI??
  20.     'PRINT "Player Guesses "; PlayerGuess
  21.  
  22.     'if PlayerGuess = 0 then goto [restart]  ' GOOD! we split first guess of 50 both ways!
  23.     IF PlayerGuess < 1 OR PlayerGuess > 100 THEN
  24.         PRINT "Your guess is out of range of this game."
  25.         _DELAY 2
  26.         GOTO cont
  27.     END IF
  28.     IF INSTR(guesses$, RIGHT$("000" + STR$(PlayerGuess), 3)) THEN
  29.         PRINT "You've guessed that number already."
  30.         _DELAY 2
  31.         GOTO cont
  32.     END IF
  33.     guesses$ = guesses$ + "," + RIGHT$("000" + STR$(PlayerGuess), 3)
  34.     IF PlayerGuess > Lo AND PlayerGuess < Hi THEN
  35.         r = RND: p = 1 / (Hi - Lo - 1) ' must be inside the Lo and Hi range ie not inclusive boundaries.
  36.         IF r <= p THEN
  37.             ' PRINT "You Guessed!"
  38.             ' _DELAY 3
  39.             Guessed = 1
  40.             EXIT WHILE
  41.         ELSE
  42.             IF PlayerGuess = Hi - 1 THEN 'guess must of been too high
  43.                 'PRINT Lo, Hi, "Your guess was too high.", r, p
  44.                 Hi = PlayerGuess
  45.                 AHI = PlayerGuess
  46.             ELSE
  47.                 IF PlayerGuess = Lo + 1 THEN
  48.                     'PRINT Lo, Hi, "Your guess was too low.", r, p
  49.                     Lo = PlayerGuess
  50.                     ALO = PlayerGuess
  51.                 ELSE 'toss coin if too high or low
  52.                     IF RND < .5 THEN
  53.                         'PRINT Lo, Hi, "Your guess was too low.", r, p
  54.                         Lo = PlayerGuess
  55.                         ALO = PlayerGuess
  56.                     ELSE
  57.                         'PRINT Lo, Hi, "Your guess was too high.", r, p
  58.                         Hi = PlayerGuess
  59.                         AHI = PlayerGuess
  60.                     END IF
  61.                 END IF
  62.             END IF
  63.         END IF
  64.     ELSE 'going wrong way with guessing, not narrowing down with current guess
  65.         'if PlayerGuess >= Hi then Print "Your guess was too high." else print "Your guess was too low."
  66.         '_DELAY 2
  67.     END IF
  68.     cont:
  69.     'PRINT Lo, Hi, ALO, AHI 'OK that blunder was pretty dumb!
  70.     'INPUT "Press enter to continue..."; wait$
  71. IF Guessed <> 1 THEN
  72.     BEEP
  73.     PRINT "Yikes! Programming error, did not find secret number."
  74.     programErrors = programErrors + 1
  75.     secrets(PlayerGuess) = secrets(PlayerGuess) + 1
  76. trial = trial + 1
  77. IF trial < 10000 THEN GOTO restart
  78.  
  79. PRINT "Secret Numbers results:"
  80. PRINT "Program errors = "; programErrors
  81. low = 10000
  82. FOR i = 1 TO 100
  83.     PRINT i, secrets(i)
  84.     tot = tot + secrets(i)
  85.     IF secrets(i) < low THEN low = secrets(i): saveLowI = i
  86.     IF secrets(i) > high THEN high = secrets(i): saveHighI = i
  87.     IF i MOD 20 = 0 THEN
  88.         INPUT "Press enter to continue... "; w$
  89.         CLS
  90.     END IF
  91. PRINT "Total "; tot
  92. PRINT " Lowest count "; low; " for i = "; saveLowI
  93. PRINT "Highest count "; high; " for i = "; saveHighI
  94.  

So there it is so far for those of you into esoteric program problems :)
« Last Edit: October 13, 2020, 01:00:56 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #25 on: October 13, 2020, 07:17:29 pm »
My independent test confirms tsh73 report is correct, the graph of the distribution of jump way up at the two ends:
Code: QB64: [Select]
  1. ' Hi Lo Game WO Secret Number Test Random Guessing Distribution  B+ 2020-10-13
  2.  
  3. ' Check tsh73 report of wackiness for pure random guessing.
  4. ' So we aren't here all day waiting for results of 1000 tests
  5. ' let us store all the guess numbers into a deck.
  6. ' Shuffle the deck before each round and use 100 numbers WITHOUT REPEAT
  7. ' to get that secret number established! That should save us a ship load
  8. ' of time and still produce results of pure random guesses.
  9.  
  10. ' 2020-10-13 trans JB code to QB64
  11.  
  12. DEFINT A-Z
  13. DIM secrets(100) ' Check distribution of answers, also checking if we fail to arrive at answer.
  14. DIM rg(100) '      Get our random guesses in a row! Here is our Deck!
  15. FOR i = 1 TO 100 ' Create our deck of random numbers to test, rg stands for Random Guess
  16.     rg(i) = i
  17.  
  18. restart:
  19. ' reinitialize all that is necessary start by reshuffle rg()
  20. FOR i = 100 TO 2 STEP -1 'forget about 0 leave it alone
  21.     tmp = rg(i)
  22.     r = INT(RND * i) + 1
  23.     rg(i) = rg(r)
  24.     rg(r) = tmp
  25. rIdx = 1 'reset deck index
  26. Hi = 101: Lo = 0 '  reset, make these higher and lower than what the secret number can be
  27. guesses$ = "" '     track what has been guessed
  28. Guessed = 0 '     flag the number has been established!
  29.  
  30. WHILE Hi - Lo > 1 ' Begin rounds of guesses for number
  31.  
  32.     PlayerGuess = rg(rIdx) ' 1 of 100 pure random guesses
  33.     rIdx = rIdx + 1
  34.     'PRINT "Player Guesses "; PlayerGuess
  35.  
  36.     'if PlayerGuess = 0 then goto restart  ' GOOD! we split first guess of 50 both ways!
  37.     IF PlayerGuess < 1 OR PlayerGuess > 100 THEN 'not going to happen
  38.         GOTO cont
  39.     END IF
  40.     IF INSTR(guesses$, RIGHT$("000" + STR$(PlayerGuess), 3)) THEN 'not going to happen
  41.         GOTO cont
  42.     END IF
  43.     guesses$ = guesses$ + "," + RIGHT$("000" + STR$(PlayerGuess), 3) 'wasting time but...
  44.     IF PlayerGuess > Lo AND PlayerGuess < Hi THEN
  45.         r = RND: p = 1 / (Hi - Lo - 1) ' must be inside the Lo and Hi range ie not inclusive boundaries.
  46.         IF r <= p THEN
  47.             'PRINT "You guessed it!"
  48.             Guessed = 1
  49.             EXIT WHILE
  50.         ELSE
  51.             IF PlayerGuess = Hi - 1 THEN 'guess must of been too high
  52.                 'print Lo, Hi, "Your guess was too high.", r, p
  53.                 Hi = PlayerGuess
  54.             ELSE
  55.                 IF PlayerGuess = Lo + 1 THEN
  56.                     'print Lo, Hi, "Your guess was too low.", r, p
  57.                     Lo = PlayerGuess
  58.                 ELSE 'toss coin if too high or low
  59.                     IF RND < .5 THEN
  60.                         'print Lo, Hi, "Your guess was too low.", r, p
  61.                         Lo = PlayerGuess
  62.                     ELSE
  63.                         'print Lo, Hi, "Your guess was too high.", r, p
  64.                         Hi = PlayerGuess
  65.                     END IF
  66.                 END IF
  67.             END IF
  68.         END IF
  69.     ELSE 'going wrong way with guessing, not narrowing down with current guess this will happen allot!!!
  70.         IF PlayerGuess >= Hi THEN
  71.             'Print "Your guess was too high."
  72.         ELSE
  73.             'print "Your guess was too low."
  74.         END IF
  75.     END IF
  76.     cont:
  77.     'INPUT "Press enter to continue..."; wait$
  78. IF Guessed <> 1 THEN
  79.     'PRINT "Yikes! Programming error, did not find secret number."
  80.     programErrors = programErrors + 1
  81.     secrets(PlayerGuess) = secrets(PlayerGuess) + 1
  82. trial = trial + 1
  83. IF trial < 10000 THEN GOTO restart
  84.  
  85. 'report results
  86. PRINT "Secret Numbers results:"
  87. PRINT "Program errors = "; programErrors
  88. low = 1000
  89. FOR i = 1 TO 100
  90.     PRINT i, secrets(i) 'that's right in JB you can scroll output screen to review all 100
  91.     tot = tot + secrets(i)
  92.     IF secrets(i) < low THEN low = secrets(i): saveLowI = i
  93.     IF secrets(i) > high THEN high = secrets(i): saveHighI = i
  94.     IF i MOD 20 = 0 THEN
  95.         INPUT " Press enter to cont..."; w$
  96.         CLS
  97.     END IF
  98. PRINT "Total "; tot
  99. PRINT " Lowest count "; low; " for i = "; saveLowI
  100. PRINT "Highest count "; high; " for i = "; saveHighI
  101.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Hi Lo without Secret Number?
« Reply #26 on: October 14, 2020, 08:10:16 pm »
One caveat:  I haven't tried any of the code in this topic yet, to actually see what the heck type of game we're supposed to be making.  I didn't want to be inspired (or limited) by looking over anyone else's work first.  Instead, I tried to make a little program which does a magic number, without having a magic number, like I understood from bplus's posts..

Regardless of whether or not this is quite what we were looking for, here's a Steve Magic Number (without a magic number) program for everyone to enjoy:

Code: QB64: [Select]
  1. min = 1: max = 100
  2.  
  3. PRINT "Guess my magic number.  It's between 1 and 100!"
  4. PRINT "If you guess high, I'll tell you to guess lower,"
  5. PRINT "and if you guess low, I'll tell you to guess higher."
  6.  
  7.  
  8.     NumberOfGuesses = NumberOfGuesses + 1
  9.     PRINT
  10.     PRINT "How many guesses will it take for you to find my number?"
  11.     PRINT "Let's find out! Give me your Guess #"; NumberOfGuesses;
  12.     INPUT " "; Guess
  13.     result = 0
  14.     IF Guess < min THEN result = 1
  15.     IF Guess > max THEN result = -1
  16.     IF result = 0 THEN 'it's a good guess, progressing the game.
  17.         target = (min + max) \ 2
  18.         IF Guess >= target THEN
  19.             IF min - max = 0 THEN result = 0 ELSE min = Guess + 1: result = 1
  20.         ELSE
  21.             max = Guess - 1: result = -1
  22.         END IF
  23.     END IF
  24.     COLOR 4
  25.     IF result < 0 THEN
  26.         PRINT "PLEASE GUESS LOWER"
  27.     ELSEIF result > 0 THEN
  28.         PRINT "PLEASE GUESS HIGHER"
  29.     ELSE
  30.         PRINT "YEP!"
  31.         PRINT "My secret number was "; Guess
  32.         COLOR 7
  33.         END
  34.     END IF
  35.     COLOR 15
  36.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #27 on: October 14, 2020, 09:32:17 pm »
Quote
I haven't tried any of the code in this topic yet, to actually see what the heck type of game we're supposed to be making.  I didn't want to be inspired (or limited) by looking over anyone else's work first.  Instead, I tried to make a little program which does a magic number, without having a magic number, like I understood from bplus's posts.

I don't like to be influenced either, try the challenge raw first, see what first impressions will bring up.

Yeah Steve, that's going the right way now but the game plays the same over and over and over (because I play same numbers over and over, I always start at 50 then 75 or 25...)  I don't think RANDOMIZE TIMER would even help.

Also I am guessing the game will always take 6 guesses, that's as cruel as my version I posted as joke. You could just count the player's guesses and give them the game after a max of 7 but could be after any guess 1 to 7 if they were all different. Man! that would meet the criteria and produce a wide range of secret numbers ultimately established at the end of the game. Wish I thought of that days ago, I just found a Hi Lo Game without Secret Number with much improved frequency distribution.

Steve thanks for hanging in there with this crazy stuff!

Oh I should try different number starts, oh boy!
  [ You are not allowed to view this attachment ]  
« Last Edit: October 14, 2020, 09:34:55 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Hi Lo without Secret Number?
« Reply #28 on: October 14, 2020, 09:54:54 pm »
Who ever said we used integers?  :P

How the heck did you get stuck between 29 and 30?  I’ll have to dig into that issue.

And it’s only 6 or 7 guesses, if you narrow it down by a binary pattern.  50, +/- 25, +/- 12, +/- 6, +/- 3, +/- 1, +/- 1.

When I came up with this little concept, the idea was basically: How can the AI stretch out the game to tease the player the longest, making them use as many guesses as possible?

BEST game should be 6-7 guesses.  Worst game, could be forever, if you don’t read the instructions ((or get stuck in and endless loop).

I’ll play around a bit tomorrow, and see what the glitch is, and I might even toss in a random target for you to shoot at with it, just so it won’t be quite as easy to tell the computer is cheating.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Hi Lo without Secret Number?
« Reply #29 on: October 14, 2020, 10:18:34 pm »
Quote
You could just count the player's guesses and give them the game after a max of 7 but could be after any guess 1 to 7 if they were all different. Man! that would meet the criteria and produce a wide range of secret numbers ultimately established at the end of the game. Wish I thought of that days ago, I just found a Hi Lo Game without Secret Number with much improved frequency distribution.

On 2nd thought no that won't work. You have to pay attention to players guesses and remain consistent in what you say with go higher or go lower, so the number still has to be narrowed down and you have to be careful in the narrowing down. I am pretty sure you have to test if 1 away from Lo or Hi and if it's going to be reported as a miss then only one way to go with narrowing down, no random up or down there. Maybe the glitch with Steve's code?

I was going to post my revised and improved game but now I think I will wait :)
Teaser: it has just the frequency distribution I was hoping to see of secret numbers established at end of each game ie spread pretty level from 1 to 100.
« Last Edit: October 14, 2020, 10:22:25 pm by bplus »