' Hi Lo Game WO Secret Number 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
IF PlayerGuess
= Hi
- 1 THEN 'guess must of been too high 'print Lo, Hi, "Your guess was too high.", r, p
Hi = PlayerGuess
'print Lo, Hi, "Your guess was too low.", r, p
Lo = PlayerGuess
ELSE 'toss coin if too high or low 'print Lo, Hi, "Your guess was too low.", r, p
Lo = PlayerGuess
'print Lo, Hi, "Your guess was too high.", r, p
Hi = 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 = 1000
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