Guess My Number
#1
This is probably the oldest BASIC game I've ever made back in High School in the 80's. I was bored today so I threw it together again with QB64. 
Guess the computer's number from 1 to 100. It adds up how many tries you take. 

Code: (Select All)
start:
Randomize Timer
number = Int(Rnd * 100) + 1
tries = 0
Cls
Do
    Print: Print
    tries = tries + 1
    Print tries; ". ";
    Input "Guess My Number (1-100): ", g
    If g = number Then
        Print: Print "Correct!"
        Print: Print "It took you "; tries; " tries."
        Print: Input "Again (Y/N)?", ag$
        If Left$(ag$, 1) = "y" Or Left$(ag$, 1) = "Y" Then GoTo start:
        End
    End If
    If g > number Then Print: Print "Your number is too high."
    If g < number Then Print: Print "Your number is too low."
Loop
Reply
#2
Pretty complex!
My first "program" was a horizontal line of about 10 dots at the right of the screen, that slowly moved across the screen and disappeared on the left, then a message underneath that said "Dirty little grub!"
It never got published, despite the obvious technical skills involved.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply
#3
Here is one-liner version (double parking with colons):
Code: (Select All)
1 If U = S Then S = Int(Rnd * 98) + 1: GoTo 1 Else If U <> S Then Input "0<Guess<99="; U: If U = S Then Print "=": GoTo 1 Else If U < S Then Print "+": GoTo 1 Else Print "-": GoTo 1
Thanks to DANILIN
b = b + ...
Reply
#4
Thanks B+, that's impressive. Smile
Reply
#5
Guess Number 2019... 2021
https://qb64forum.alephc.xyz/index.php?topic=3999

Computer guessing from Milliard
https://qb64forum.alephc.xyz/index.php?t...#msg133452

Code: (Select All)
t = 0: h1 = 0: h2 = 10^7: RANDOMIZE TIMER ' DANILIN daMilliard.bas
human = INT(RND*h2) 'human
comp = 1 'INT(RND*h2) 'comp
10 t = t+1: PRINT t; "human ="; human; "     comp ="; comp;
IF comp < human THEN PRINT "MORE": a = comp: comp = INT((comp+h2)/2): h1 = a: GOTO 10
IF human < comp THEN PRINT "less": a = comp: comp = INT((h1+comp)/2): h2 = a: GOTO 10
PRINT "win by "; t; " steps"
END

Code: (Select All)
h1=0: h2=10^7: t=1: f=0: Randomize Timer ' DANILIN daMilliard.bas
human = Int(Rnd*h2) 'human
comp = Int(Rnd*h2) 'comp
While f < 1
Print t; "human ="; human; "     comp ="; comp;
If comp < human Then
Print " MORE": a=comp: comp=Int((comp+h2)/2): h1=a
  Else If human < comp Then
  Print " less": a=comp: comp=Int((h1+comp)/2): h2=a
    Else If human=comp Then
    Print " win by "; t; " steps": f=1
End If: End If: End If: t = t + 1
Wend: End

Code: (Select All)
1  human = 1326126     comp = 1928303  less
2  human = 1326126     comp = 964151  MORE
3  human = 1326126     comp = 1446227  less
4  human = 1326126     comp = 1205189  MORE
5  human = 1326126     comp = 1325708  MORE
6  human = 1326126     comp = 1385967  less
7  human = 1326126     comp = 1355837  less
8  human = 1326126     comp = 1340772  less
9  human = 1326126     comp = 1333240  less
10  human = 1326126     comp = 1329474  less
11  human = 1326126     comp = 1327591  less
12  human = 1326126     comp = 1326649  less
13  human = 1326126     comp = 1326178  less
14  human = 1326126     comp = 1325943  MORE
15  human = 1326126     comp = 1326060  MORE
16  human = 1326126     comp = 1326119  MORE
17  human = 1326126     comp = 1326148  less
18  human = 1326126     comp = 1326133  less
19  human = 1326126     comp = 1326126  win by 19 steps

+ C# + Python version

OnLine Execute

https://jdoodle.com/ia/vY4
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic

Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
Reply
#6
One of my first programs, on Radio Shack TRS-80 Color Computer 2, was a cross between Space Invaders and Defender. It put the player's ship on the screen with one enemy. The player could only move forward to the right-hand side of the small green screen and then wrapped around to the left-hand side. Whenever the bad guy was shot at and hit, the program did a ridiculous blink of the whole screen for a few seconds, with sound. The logic for the bad guy to move around was bad. No wait, another one that I did was alike but the bad guy was always at a random location. Not very playable. It was less playable than the contribution in the QB64 Samples by the programmer from Argentina, in which the bad guy was called "Commander Garri". Always updated with "CLS" LOL.

I actually did a remake of the "random location bad guy" game with QB64 SDL version. However it chooses ten locations that the enemy keeps shuffling among. I created a MOD tracker music file especially to play in that game too.

Also I wanted to go further with a "game" found in the Coco2 manual, which was "text mode" graphics and responded to joystick. It was supposed to be a spaceship plotting through stars to land on a planet. The problem was it always put the planet on a specific corner of the screen and the player only had to set the joystick in like manner so that, "I won." That was with the "cheap" joystick; the "Color Joystick" presented the other problem of having the ability to lock to the center position. "Whoa we're halfway there, oh-ho! Living on a prayer" ROFLMAO. When I tried to change it, it was one of my very first attempts to introduce real animation in an arcade-style game. Another thing was that Coco2 didn't come with Extended BASIC and therefore had to use "PEEK()" to read the joystick button; unlike for reading the positions it didn't have a dedicated command to read the buttons.

The manual also had this program called an "inventory storage", which used string arrays. It employed the slow bubble sort too. I was very ignorant at the time to realize it was the beginning of a text editor like "EDLIN" for MS-DOS, however had to change "INPUT" requests into those that could have used "INKEY$".
Reply
#7
mnrvovrfc, you might like my Tech Invaders 4 game. It's kinda like a mix between Space Invaders and Galaga. It uses the mouse. You can get it on the forum here:

https://staging.qb64phoenix.com/showthre...h+Invaders
Reply
#8
That's pretty cool Danilin!
Reply
#9
Thumbs Up 
(09-25-2022, 08:21 PM)SierraKen Wrote: mnrvovrfc, you might like my Tech Invaders 4 game. It's kinda like a mix between Space Invaders and Galaga. It uses the mouse. You can get it on the forum here:

https://staging.qb64phoenix.com/showthre...h+Invaders
I have checked it out and it's very good. Especially I like the "boss" logic. Thank you.
Reply
#10
Program dafindnum.bas guesses unanswered number less or more
by starting from middle of list and comparing odd and even ones separately

Visual:
Code: (Select All)
123456789    
    5
    5
    5 7
  3 5 7
  3 5 7 9
1 3 5 7 9
1 3 567 9
1 3 567 9
1 3 56789
1 3456789
1 3456789
123456789

Won if you guessed less than number before attempt
or lost if you guessed from beginning faster

It is effective if distribution of guesses is normal undulating
however how to evaluate result of integral is still unknown

However experimental program is not optimal
and it is possible to include a step greater than 2

Code: (Select All)
n = 55: Randomize Timer: a = Int(Rnd * (n - 1)) + 1 ' dafindnum.bas
start = Int(1 + n / 2) ' https://staging.qb64phoenix.com/showthread.php?tid=900
Print "n= "; n, "a= "; a: Print: s = 0

For i = 0 To 1: For j = 0 To n / 4

    t = Int(start + j * 2) + i
    If t > n Then 5
    s = s + 1: Print s, t
    If t = a Then 25

    5 t = Int(start - j * 2) + i
    If t < 1 Then 15
    s = s + 1: Print s, t
    If t = a Then 25

15 Next: Next ': Print "NO...": End

25 Print: Print "Step="; s, "Guess="; a, "Max="; n
If s < a Then Print "WIN" Else If s > a Then Print "Lose" Else Print "Draw"
End

Checking 1000 or a dozen thousand showed:
Draw 25% and Lose 37.5% and Win 37.5%

Code: (Select All)
n = 3*10^4: start = Int(1 + n / 2) ' dafindnum99.bas
w = 0: l = 0: d = 0 ' Win Lose Draw

For a = 1 To n: s = 0
    For i = 0 To 1 ' even \ odd
        For j = 0 To n / 4

            t = Int(start + j * 2) + i ' right
            If t > n Then 5
            s = s + 1
            If t = a Then 25

            5 t = Int(start - j * 2) + i ' left
            If t < 1 Then 15
            s = s + 1
            If t = a Then 25

    15 Next: Next ': Print "NO..." : End

    25 Print "Max="; n, "Guess="; a, "Step="; s,
    If s < a Then Print "WIN": w = w + 1 Else If s > a Then Print "Lose": l = l + 1 Else Print "Draw": d = d + 1
Next a: Print: Print "Win= "; w, "Lose= "; l, "Draw= "; d
End

So if a draw is considered a win then algorithm it is effective

[Image: guess22.png]

[Image: guess99.png]

picture: 10 kB
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic

Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
Reply




Users browsing this thread: 4 Guest(s)