Before the river of time travels too far, here is my revised version of Hi Lo Game that has no secret number from start. The number gets established later by careful applications of RND s.t. the final secret numbers established cover fairly evenly the number range 1 to 100 like int(rnd*100) + 1 for secret number would have done.
_TITLE "Hi Lo Game without Secret Number v2" 'B+ 2020-10-13 ' trans from JB 2020-10-11 minimal changes
DIM hi
, lo
, guesses$
, playerGuess
, guessed
, range
, again$
restart:
hi = 101: lo = 0 '<<<< make these higher and lower than what the secret number can be
guesses$ = ""
INPUT "Guess Number 1 to 100, Enter your guess "; playerGuess
'if PlayerGuess = 0 then goto [restart] ' GOOD! we split first guess of 50 both ways!
IF playerGuess
< 1 OR playerGuess
> 100 THEN PRINT "Your guess is out of range of this game." PRINT "You've guessed that number already." guesses$
= guesses$
+ "," + RIGHT$("000" + STR$(playerGuess
), 3) IF playerGuess
> lo
AND playerGuess
< hi
THEN ' must be inside the Lo and Hi range ie not inclusive boundaries.
guessed = 1
PRINT "Your guess was low." lo = lo + 1
PRINT "Your guess was high." hi = hi - 1
'p < guess = (guess - lo -1) / range
range = hi - lo - 1
PRINT lo
, hi
, "Your guess was too high." hi = playerGuess
PRINT lo
, hi
, "Your guess was too low." lo = playerGuess
cont:
IF guessed
<> 1 THEN PRINT "Yikes! Programming error, did not find secret number." PRINT:
INPUT "press Enter to go again, any other + Enter to quit "; again$
And here are 2 frequency testers in one, just change what is commented out for PlayerGuess:
_TITLE "Hi Lo Game wo secret Test Distribution" ' B+ 2020-10-10 works now DIM secrets
(100) 'check distribution of answers, also checking if we fail to arrive at answer DIM hi
, lo
, guesses$
, alo
, ahi
, guessed
, playerGuess
, range
, programErrors
, trial
, low
, i
, tot
, saveLowI
, high
, saveHighI
, w$
restart:
hi = 101: lo = 0 '<<<< make these higher and lower than what the secret number can be
guesses$ = ""
guessed = 0
ahi = 101
'input "Guess Number 1 to 100, Enter your guess "; PlayerGuess
'use AI to guess
'make all the guesses way too high ie ride the AHI down 1 by 1
'ahi = ahi - 1
'playerGuess = ahi
playerGuess
= INT((hi
- lo
) / 2) + lo
'debug what the heck is going on with ALO AHI?? 'PRINT "Player Guesses "; playerGuess
'if PlayerGuess = 0 then goto [restart] ' GOOD! we split first guess of 50 both ways!
IF playerGuess
< 1 OR playerGuess
> 100 THEN PRINT "Your guess is out of range of this game." PRINT "You've guessed that number already." guesses$
= guesses$
+ "," + RIGHT$("000" + STR$(playerGuess
), 3) IF playerGuess
> lo
AND playerGuess
< hi
THEN ' must be inside the Lo and Hi range ie not inclusive boundaries.
guessed = 1
'PRINT "Your guess was low."
lo = lo + 1
'PRINT "Your guess was high."
hi = hi - 1
'p < guess = (guess - lo -1) / range
range = hi - lo - 1
' PRINT lo, hi, "Your guess was too high."
hi = playerGuess
'PRINT lo, hi, "Your guess was too low."
lo = playerGuess
ELSE 'going wrong way with guessing, not narrowing down with current guess 'IF playerGuess >= hi THEN PRINT "Your guess was too high." ELSE PRINT "Your guess was too low."
cont:
'PRINT lo, hi, alo, ahi 'OK that blunder was pretty dumb!
'INPUT "Press enter to continue..."; w$
PRINT "Yikes! Programming error, did not find secret number." programErrors = programErrors + 1
secrets(playerGuess) = secrets(playerGuess) + 1
trial = trial + 1
PRINT "Secret Numbers results:" PRINT "Program errors = "; programErrors
low = 10000
tot = tot + secrets(i)
IF secrets
(i
) < low
THEN low
= secrets
(i
): saveLowI
= i
IF secrets
(i
) > high
THEN high
= secrets
(i
): saveHighI
= i
INPUT "Press enter to continue... "; w$
PRINT " Lowest count "; low;
" for i = "; saveLowI
PRINT "Highest count "; high;
" for i = "; saveHighI
And this is the frequency tester in which the V2 Game code (the AI deciding if guess too high or low or correct) was developed using a deck of numbers from 1 to 100 shuffled for guessing randomly without repetition.
' Hi Lo Game WO Secret Number v2 Test Random Guessing Distribution B+ 2020-10-13
' Check tsh73 report of wackiness for pure random guessing.
' So we aren't here all day waiting for results of 1000 tests
' let us store all the guess numbers into a deck.
' Shuffle the deck before each round and use 100 numbers WITHOUT REPEAT
' to get that secret number established! That should save us a ship load
' of time and still produce results of pure random guesses.
' 2020-10-13 trans JB code to QB64
DIM secrets
(100) ' Check distribution of answers, also checking if we fail to arrive at answer. DIM rg
(100) ' Get our random guesses in a row! Here is our Deck! FOR i
= 1 TO 100 ' Create our deck of random numbers to test, rg stands for Random Guess rg(i) = i
restart:
' reinitialize all that is necessary start by reshuffle rg()
FOR i
= 100 TO 2 STEP -1 'forget about 0 leave it alone tmp = rg(i)
rg(i) = rg(r)
rg(r) = tmp
rIdx = 1 'reset deck index
Hi = 101: Lo = 0 ' reset, make these higher and lower than what the secret number can be
guesses$ = "" ' track what has been guessed
Guessed = 0 ' flag the number has been established!
WHILE Hi
- Lo
> 1 ' Begin rounds of guesses for number
PlayerGuess = rg(rIdx) ' 1 of 100 pure random guesses
rIdx = rIdx + 1
'PRINT "Player Guesses "; PlayerGuess
'if PlayerGuess = 0 then goto restart ' GOOD! we split first guess of 50 both ways!
IF PlayerGuess
< 1 OR PlayerGuess
> 100 THEN 'not going to happen guesses$
= guesses$
+ "," + RIGHT$("000" + STR$(PlayerGuess
), 3) 'wasting time but... IF PlayerGuess
> Lo
AND PlayerGuess
< Hi
THEN r
= RND: p
= 1 / (Hi
- Lo
- 1) ' must be inside the Lo and Hi range ie not inclusive boundaries. 'PRINT "You guessed it!"
Guessed = 1
'PRINT "Your guess was low."
Lo = Lo + 1
'PRINT "Your guess was high."
Hi = Hi - 1
'p < guess = (guess - lo -1) / range
range = Hi - Lo - 1
'PRINT Lo, Hi, "Your guess was too high."
Hi = PlayerGuess
'PRINT Lo, Hi, "Your guess was too low."
Lo = PlayerGuess
ELSE 'going wrong way with guessing, not narrowing down with current guess this will happen allot!!! 'Print "Your guess was too high."
'print "Your guess was too low."
cont:
'INPUT "Press enter to continue..."; wait$
'PRINT "Yikes! Programming error, did not find secret number."
programErrors = programErrors + 1
secrets(PlayerGuess) = secrets(PlayerGuess) + 1
trial = trial + 1
'report results
PRINT "Secret Numbers results:" PRINT "Program errors = "; programErrors
low = 10000
PRINT i
, secrets
(i
) 'that's right in JB you can scroll output screen to review all 100 tot = tot + secrets(i)
IF secrets
(i
) < low
THEN low
= secrets
(i
): saveLowI
= i
IF secrets
(i
) > high
THEN high
= secrets
(i
): saveHighI
= i
INPUT " Press enter to cont..."; w$
PRINT " Lowest count "; low;
" for i = "; saveLowI
PRINT "Highest count "; high;
" for i = "; saveHighI